Implement NetBox DB provisioning and deployment via GitOps with 1Password Operator #192
+302
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds GitOps-based database provisioning for NetBox using 1Password Operator for credential management, with namespace isolation between admin and runtime credentials.
Architecture
Three-phase sync wave orchestration:
netbox-secrets→ Provision 1Password-backed secrets ininfra-netboxnetbox-db-provisioner→ Run PreSync hook to create database/role indb-postgresnetbox→ Deploy applicationNamespace isolation:
db-postgres: Containspostgres-adminandnetbox-db-credentials(admin context)infra-netbox: Containsnetbox-db-credentials,netbox-redis-credentials,netbox-django-secret,netbox-superuser(app context)Implementation
DB Provisioning (
k8s/db-provisioning/netbox/)--setvariables + PostgreSQLformat(%I, %L)for SQL injection protectionHookSucceededApp Configuration (
argocd/apps/infra/netbox.yml)existingSecretfor all credentialsexternalDatabase,tasksDatabase,cachingDatabase, Django secret, and superuserOnePasswordItems
db-postgresfor provisioning, one ininfra-netboxfor runtimevaults/HomeLab/items/*for centralized credential managementSecurity
Pattern for Future Apps
Copy
k8s/db-provisioning/netbox/andk8s/infra/netbox/, update:Original prompt
This section details on the original issue you should resolve
<issue_title>NetBox DB Provisioning + App Deployment via GitOps + 1Password Operator</issue_title>
<issue_description>## Goals
db-postgresnamespace.infra-netbox).Non-goals
pg_hba.conf(we already recovered; now we operate normally).Repo Layout
Create two new GitOps apps:
(Exact placement is flexible; the key is separation by concern:
db-provisioning/*vsinfra/*.)Prereqs
coachlight_adminexists in Postgres and has superuser (or at least createdb/createrole).1Password Items Required (in 1Password)
Create these items in 1Password (single source of truth):
A)
postgres-admin(DBA identity)Fields:
username:coachlight_adminpassword:<strong password>B)
netbox-db-credentials(app identity)Fields:
username:netboxpassword:<strong password>C)
netbox-redis-credentials(optional if Redis requires auth)Fields:
password:<strong password>D)
netbox-django-secretFields:
secretKey:<strong random string>E)
netbox-superuserFields:
password:<strong password>(Email can stay in Helm values.)
Argo Application 1: DB Provisioning (lives with database)
File:
argocd/apps/db/netbox-db-provisioner.ymldb-postgres"15"if NetBox is"20")Responsibilities
Create secrets in
db-postgresusing OnePasswordItem:postgres-adminnetbox-db-credentialsRun a Job that:
netboxif missingnetboxif missingManifest:
k8s/db-provisioning/netbox/00-onepassworditems-db-postgres.yamlCreate Two OnePasswordItems in namespace
db-postgres:postgres-admin→ points at 1Password itempostgres-adminnetbox-db-credentials→ points at 1Password itemnetbox-db-credentialsNaming contract:
username,password)Manifest:
k8s/db-provisioning/netbox/10-netbox-db-provision-job.yamlJob requirements
Namespace:
db-postgresUses a container with
psqlavailable (Bitnami postgres image is fine).Reads env from Secrets:
POSTGRES_ADMIN_USER/POSTGRES_ADMIN_PASSWORDfrompostgres-adminsecret keysusername/passwordNETBOX_DB_USER/NETBOX_DB_PASSWORDfromnetbox-db-credentialssecret keysusername/passwordConnects to the Postgres service:
postgres-postgresql.db-postgres.svc.cluster.local5432postgres(maintenance DB)Runs idempotent SQL.
SQL contract (idempotent)
Run via
psqlwithON_ERROR_STOP=1.Use one transaction-safe sequence:
NETBOX_DB_PASSWORD(rotate-friendly)Implementation detail: use
DO $$ ... $$;blocks for “IF NOT EXISTS” and always runALTER ROLE ... PASSWORD.Example SQL logic (Copilot should implement exactly this behavior):
DOcreate role only if not existsALTER ROLE netbox WITH LOGIN PASSWORD '<from secret>';DOcreate database only if not existsALTER DATABASE netbox OWNER TO netbox;(safe even if already)GRANT CONNECT ON DATABASE netbox TO netbox;Argo hook behavior
Choose ONE:
Option 1 (recommended): normal Job, idempotent
Option 2: Argo PreSync hook Job
Add annotations:
argocd.argoproj.io/hook: PreSyncargocd.argoproj.io/hook-delete-policy: HookSucceededPros: runs automatically before sync and cleans up
Cons: reruns more often; still fine because SQL is idempotent
Pick Option 2 if you want strict ordering every sync; otherwise Option 1.
TTL
Set `spec.ttlSecondsA...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.