Skip to content

Commit b0c6fbb

Browse files
authored
fix(bootstrap): define CODER_ADMIN_* in coder-init-admin
2 parents c61feb1 + 11ce2a8 commit b0c6fbb

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
@@ -489,8 +489,11 @@ in
489489
programs.git.config.safe.directory = [ "/etc/nixos-repo" ];
490490

491491
# ── Coder server ──────────────────────────────────────────────────────────
492-
# Base env vars live here. Secrets (admin creds, OAuth, etc.) are merged in
493-
# via systemd.services.coder.environment in hosts/<host>/local.nix; no EnvironmentFile.
492+
# Base env vars live here. Server secrets (e.g. OAuth) are merged in via
493+
# systemd.services.coder.environment in hosts/<host>/local.nix; no
494+
# EnvironmentFile. Admin bootstrap creds (CODER_ADMIN_*) are NOT set here —
495+
# they live on coder-init-admin.service so they stay off the long-running
496+
# server's environment.
494497
systemd.services.coder = {
495498
description = "Coder Server";
496499
wantedBy = [ "multi-user.target" ];
@@ -538,7 +541,9 @@ in
538541
};
539542

540543
# ── Admin user bootstrap ──────────────────────────────────────────────────
541-
# Reads CODER_ADMIN_* from coder.service environment (set via local.nix).
544+
# Reads CODER_ADMIN_* from this service's own environment (set via
545+
# local.nix as systemd.services.coder-init-admin.environment), keeping the
546+
# admin credentials off the long-running coder.service.
542547
# Creates a local admin account once; sentinel prevents re-running.
543548
# If CODER_ADMIN_EMAIL is unset, skips and directs user to the browser wizard.
544549
systemd.services.coder-init-admin = {
@@ -547,8 +552,10 @@ in
547552
after = [ "coder.service" ];
548553
requires = [ "coder.service" ];
549554

550-
# Inherit the full coder.service environment so CODER_ADMIN_* and
551-
# CODER_PG_CONNECTION_URL are available without duplication.
555+
# Inherit the coder.service environment so CODER_PG_CONNECTION_URL (and the
556+
# other server vars) are available without duplication. The CODER_ADMIN_*
557+
# credentials are merged in on top via the coder-init-admin.environment
558+
# definition in hosts/<host>/local.nix (NixOS merges attrset options).
552559
inherit (config.systemd.services.coder) environment;
553560

554561
serviceConfig = {
@@ -687,7 +694,10 @@ in
687694
];
688695
requires = [ "postgresql.service" ];
689696

690-
inherit (config.systemd.services.coder) environment;
697+
# Step 8 mints a session token using CODER_ADMIN_EMAIL/PASSWORD, so pull in
698+
# the coder-init-admin environment (which itself includes the coder.service
699+
# vars plus the CODER_ADMIN_* credentials from local.nix).
700+
inherit (config.systemd.services.coder-init-admin) environment;
691701

692702
serviceConfig = {
693703
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
@@ -233,11 +233,13 @@ in
233233
initialPassword = "PleaseChangeMe1234";
234234
};
235235

236-
# coder-init-admin.service reads CODER_ADMIN_* from coder.service's
236+
# coder-init-admin.service reads CODER_ADMIN_* from its own service
237237
# environment and creates a local admin on first boot, then mints a session
238238
# token and deploys the templates from /etc/nixos-repo/coderd. With these set
239-
# the Coder instance is ready to use immediately.
240-
systemd.services.coder.environment = {
239+
# the Coder instance is ready to use immediately. These admin credentials are
240+
# only needed by the bootstrap service, so they are kept off the long-running
241+
# coder.service environment.
242+
systemd.services.coder-init-admin.environment = {
241243
CODER_ADMIN_EMAIL = "admin@coder.com";
242244
CODER_ADMIN_USERNAME = "admin";
243245
CODER_ADMIN_PASSWORD = "PleaseChangeMe1234";

0 commit comments

Comments
 (0)