Skip to content

Commit 9017715

Browse files
Trolldemortedfsck
authored andcommitted
Adapt cmdline from #49, fix docker permission drop, fix readme
Closes #49 Closes #46 Closes #41
1 parent 646a6f5 commit 9017715

File tree

4 files changed

+36
-39
lines changed

4 files changed

+36
-39
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ RUN cargo +nightly build
2424
FROM debian:stretch-slim
2525
WORKDIR /enokey
2626
RUN mkdir keyfiles
27+
RUN mkdir data
2728

2829
RUN apt-get update \
2930
&& apt-get install -y libssl1.1 ca-certificates openssh-client --no-install-recommends \
3031
&& rm -rf /var/lib/apt/lists/*
3132

3233
COPY --from=build /service/enokey/target/debug/enokey .
3334
COPY ./static ./static
35+
COPY ./templates ./templates
3436
COPY ./Rocket.toml ./Rocket.toml
3537

3638
ENV ROCKET_ENV production
@@ -41,6 +43,5 @@ RUN chown -R enokey /home/enokey/
4143
RUN chown -R enokey .
4244
COPY /docker-entrypoint.sh /
4345
RUN chmod o+x /docker-entrypoint.sh
44-
USER enokey
4546
ENTRYPOINT ["/docker-entrypoint.sh"]
4647
CMD ["./enokey"]

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ version: '3'
1212
1313
services:
1414
enokey:
15-
build: .
15+
build: enoflag/enokey
1616
volumes:
1717
- ./data:/enokey/data
1818
restart: on-failure
@@ -23,9 +23,9 @@ services:
2323
- ROCKET_ENV=production
2424
- ROCKET_LOG=normal
2525
- ROCKET_SECRET_KEY=whs/vijJnEoWN9Xgf25oJDn2yUtvsNuhm0eMNxZe6CI=
26-
- SERVER_ADMIN[email protected]:8022
27-
- PSK_ADMIN=HIGHLYSECRET
28-
- SERVER_USER[email protected]
29-
- PSK_USER=NOTSOSECRET
26+
- ADMIN_SERVERS[email protected]:8022
27+
- ADMIN_PSK=HIGHLYSECRET
28+
- USER_SERVERS[email protected]
29+
- USER_PSK=NOTSOSECRET
3030
- RUST_BACKTRACE=1
3131
```

docker-entrypoint.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ cp ./data/id_ed25519 ~/.ssh/id_ed25519
1212
chmod 600 ~/.ssh/id_ed25519
1313
ssh-keygen -y -f ~/.ssh/id_ed25519 |awk '{print $1" "$2" enokey@docker"}'> ~/.ssh/id_ed25519.pub
1414
chmod 644 ~/.ssh/id_ed25519.pub
15-
16-
exec "$@"
15+
chown -R . enokey
16+
su enokey
17+
exec "$@" --admin-servers "$ADMIN_SERVERS" --admin-psk "$ADMIN_PSK" --user-servers "$USER_SERVERS" --user-psk "$USER_PSK"

src/main.rs

+26-31
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,11 @@ fn main() {
245245
let args: Vec<String> = env::args().collect();
246246
let program = args[0].clone();
247247
let mut opts = Options::new();
248-
opts.optflag(
249-
"n",
250-
"dry-run",
251-
"Do not push the generated authorized_key file",
252-
);
253248
opts.optflag("h", "help", "Print this help menu");
249+
opts.optopt("a", "admin-servers", "Set the destinations (remote server) for the admin group", "ADMIN_SERVERS");
250+
opts.optopt("p", "admin-psk", "Set the pre-shared key to add keys the admin group", "ADMIN_PSK");
251+
opts.optopt("u", "user-servers", "Set the destinations (remote server) for the user group", "USER_SERVERS");
252+
opts.optopt("q", "user-psk", "Set the pre-shared key to add keys the user group", "USER_PSK");
254253

255254
let matches = match opts.parse(&args[1..]) {
256255
Ok(m) => m,
@@ -264,41 +263,37 @@ fn main() {
264263
return;
265264
}
266265

267-
if matches.opt_present("n") {
268-
eprintln!("dry mode is currently not supported");
269-
std::process::exit(1);
270-
}
266+
{
267+
let config = &mut *CONFIG.lock().unwrap();
271268

272-
let admin_env = match env::var("SERVER_ADMIN") {
273-
Ok(admin) => parse_destinations(&admin),
274-
Err(e) => {
275-
println!("Warning: SERVER_ADMIN not set. ({})", e);
276-
Ok(vec![])
277-
}
278-
};
269+
let admin_env = match matches.opt_str("a") {
270+
Some(admin) => parse_destinations(&admin),
271+
None => {
272+
println!("Warning: No admin servers set");
273+
Ok(vec!())
274+
}
275+
};
279276

280-
let user_env = match env::var("SERVER_USER") {
281-
Ok(admin) => parse_destinations(&admin),
282-
Err(e) => {
283-
println!("Warning: SERVER_USER not set. ({})", e);
284-
Ok(vec![])
285-
}
286-
};
277+
let user_env = match matches.opt_str("u") {
278+
Some(user) => parse_destinations(&user),
279+
None => {
280+
println!("Warning: No user servers set");
281+
Ok(vec!())
282+
}
283+
};
287284

288-
{
289-
let config = &mut *CONFIG.lock().unwrap();
290285
config.user_destinations = match user_env {
291286
Ok(user_env) => user_env.clone(),
292287
Err(e) => {
293-
println!("Could not parse SERVER_USER {:?}", e);
288+
println!("Could not parse user servers: {:?}", e);
294289
return;
295290
}
296291
};
297292

298293
config.admin_destinations = match admin_env {
299294
Ok(admin_env) => admin_env.clone(),
300295
Err(e) => {
301-
println!("Could not parse SERVER_ADMIN {:?}", e);
296+
println!("Could not parse admin servers: {:?}", e);
302297
return;
303298
}
304299
};
@@ -307,13 +302,13 @@ fn main() {
307302
.admin_destinations
308303
.extend(config.user_destinations.iter().cloned());
309304

310-
config.user_psk = env::var("PSK_USER").unwrap_or_else(|e| {
311-
println!("Warning: PSK_USER not set. {:?}", e);
305+
config.user_psk = matches.opt_str("q").unwrap_or_else(||{
306+
println!("Warning: User PSK not set.");
312307
"default".to_string()
313308
});
314309

315-
config.admin_psk = env::var("PSK_ADMIN").unwrap_or_else(|e| {
316-
println!("Warning: PSK_ADMIN not set. {:?}", e);
310+
config.admin_psk = matches.opt_str("p").unwrap_or_else(||{
311+
println!("Warning: Admin PSK not set.");
317312
"default".to_string()
318313
});
319314

0 commit comments

Comments
 (0)