Skip to content

Commit 2a07285

Browse files
committed
fix(bootstrap): define CODER_ADMIN_* on coder-init-admin, not coder.service
Move the admin bootstrap credentials (CODER_ADMIN_EMAIL/USERNAME/PASSWORD) out of the long-running coder.service environment and onto the coder-init-admin.service (and its dependent coder-reset.service), so they are only present where the bootstrap actually needs them. coder-init-admin and coder-reset still inherit coder.service's environment for CODER_PG_CONNECTION_URL; the admin creds are merged in via systemd.services.coder-init-admin.environment in local.nix. GitHub OAuth vars remain on coder.service since the server reads them. Refs #29
1 parent a4f8937 commit 2a07285

4 files changed

Lines changed: 38 additions & 20 deletions

File tree

‎configuration.nix‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,11 @@ in
405405
programs.git.config.safe.directory = [ "/etc/nixos-repo" ];
406406

407407
# ── Coder server ──────────────────────────────────────────────────────────
408-
# Base env vars live here. Secrets (admin creds, OAuth, etc.) are merged in
409-
# via systemd.services.coder.environment in hosts/<host>/local.nix; no EnvironmentFile.
408+
# Base env vars live here. Server secrets (e.g. OAuth) are merged in via
409+
# systemd.services.coder.environment in hosts/<host>/local.nix; no
410+
# EnvironmentFile. Admin bootstrap creds (CODER_ADMIN_*) are NOT set here —
411+
# they live on coder-init-admin.service so they stay off the long-running
412+
# server's environment.
410413
systemd.services.coder = {
411414
description = "Coder Server";
412415
wantedBy = [ "multi-user.target" ];
@@ -454,7 +457,9 @@ in
454457
};
455458

456459
# ── Admin user bootstrap ──────────────────────────────────────────────────
457-
# Reads CODER_ADMIN_* from coder.service environment (set via local.nix).
460+
# Reads CODER_ADMIN_* from this service's own environment (set via
461+
# local.nix as systemd.services.coder-init-admin.environment), keeping the
462+
# admin credentials off the long-running coder.service.
458463
# Creates a local admin account once; sentinel prevents re-running.
459464
# If CODER_ADMIN_EMAIL is unset, skips and directs user to the browser wizard.
460465
systemd.services.coder-init-admin = {
@@ -463,8 +468,10 @@ in
463468
after = [ "coder.service" ];
464469
requires = [ "coder.service" ];
465470

466-
# Inherit the full coder.service environment so CODER_ADMIN_* and
467-
# CODER_PG_CONNECTION_URL are available without duplication.
471+
# Inherit the coder.service environment so CODER_PG_CONNECTION_URL (and the
472+
# other server vars) are available without duplication. The CODER_ADMIN_*
473+
# credentials are merged in on top via the coder-init-admin.environment
474+
# definition in hosts/<host>/local.nix (NixOS merges attrset options).
468475
inherit (config.systemd.services.coder) environment;
469476

470477
serviceConfig = {
@@ -603,7 +610,10 @@ in
603610
];
604611
requires = [ "postgresql.service" ];
605612

606-
inherit (config.systemd.services.coder) environment;
613+
# Step 8 mints a session token using CODER_ADMIN_EMAIL/PASSWORD, so pull in
614+
# the coder-init-admin environment (which itself includes the coder.service
615+
# vars plus the CODER_ADMIN_* credentials from local.nix).
616+
inherit (config.systemd.services.coder-init-admin) environment;
607617

608618
serviceConfig = {
609619
Type = "oneshot";

‎hosts/incus-vm/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Edit `hosts/$HOSTNAME/local.nix` and at minimum set:
148148
```nix
149149
services.coder-nixos.lanIp = "192.168.x.x"; # VM's primary IP
150150
151-
systemd.services.coder.environment = {
151+
systemd.services.coder-init-admin.environment = {
152152
CODER_ADMIN_EMAIL = "you@example.com";
153153
CODER_ADMIN_USERNAME = "admin";
154154
CODER_ADMIN_PASSWORD = "changeme";

‎local.nix.example‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,27 @@ in
3131
# Use the email address linked to your GitHub account so that OAuth login
3232
# merges into this admin account automatically.
3333
# Skipped if CODER_ADMIN_EMAIL is empty (complete the wizard in the browser instead).
34-
systemd.services.coder.environment = {
34+
#
35+
# These credentials live on coder-init-admin.service (the bootstrap service),
36+
# NOT coder.service, so they stay out of the long-running server's environment.
37+
systemd.services.coder-init-admin.environment = {
3538
CODER_ADMIN_EMAIL = "you@example.com"; # change this
3639
CODER_ADMIN_USERNAME = "admin";
3740
CODER_ADMIN_PASSWORD = "changeme"; # change this
38-
39-
# ── GitHub OAuth (optional) ──────────────────────────────────────────────
40-
# Leave this block commented out to use the built-in Coder GitHub App.
41-
# CODER_OAUTH2_GITHUB_CLIENT_ID = "";
42-
# CODER_OAUTH2_GITHUB_CLIENT_SECRET = "";
43-
# CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS = "true";
44-
# CODER_OAUTH2_GITHUB_DEFAULT_PROVIDER_ENABLE = "false";
45-
# CODER_OAUTH2_GITHUB_ALLOW_EVERYONE = "true";
46-
# CODER_OAUTH2_GITHUB_ALLOWED_ORGS = "my-org";
4741
};
4842

43+
# ── GitHub OAuth (optional) ────────────────────────────────────────────────
44+
# Read by the long-running coder.service. Leave this block commented out to
45+
# use the built-in Coder GitHub App.
46+
# systemd.services.coder.environment = {
47+
# CODER_OAUTH2_GITHUB_CLIENT_ID = "";
48+
# CODER_OAUTH2_GITHUB_CLIENT_SECRET = "";
49+
# CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS = "true";
50+
# CODER_OAUTH2_GITHUB_DEFAULT_PROVIDER_ENABLE = "false";
51+
# CODER_OAUTH2_GITHUB_ALLOW_EVERYONE = "true";
52+
# CODER_OAUTH2_GITHUB_ALLOWED_ORGS = "my-org";
53+
# };
54+
4955
# ── Desktop / OS login account ─────────────────────────────────────────────
5056
# SDDM / SSH login. Change with `passwd ${nixosUsername}` after first boot;
5157
# initialPassword only fires on user creation.

‎nixos/_images/box-turnkey.nix‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@
105105
initialPassword = "PleaseChangeMe1234";
106106
};
107107

108-
# coder-init-admin.service reads CODER_ADMIN_* from coder.service's
108+
# coder-init-admin.service reads CODER_ADMIN_* from its own service
109109
# environment and creates a local admin on first boot, then mints a session
110110
# token and deploys the templates from /etc/nixos-repo/coderd. With these set
111-
# the Coder instance is ready to use immediately.
112-
systemd.services.coder.environment = {
111+
# the Coder instance is ready to use immediately. These admin credentials are
112+
# only needed by the bootstrap service, so they are kept off the long-running
113+
# coder.service environment.
114+
systemd.services.coder-init-admin.environment = {
113115
CODER_ADMIN_EMAIL = "admin@coder.com";
114116
CODER_ADMIN_USERNAME = "admin";
115117
CODER_ADMIN_PASSWORD = "PleaseChangeMe1234";

0 commit comments

Comments
 (0)