Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use secrets for Nautobot SSO configuration #22

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/components/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ resources:
- argo-workflows.yaml
- argo-events.yaml
- ironic.yaml
- dexidp.yaml
1 change: 1 addition & 0 deletions components/00-namespaces/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ resources:
- nautobot.yaml
- openstack.yaml
- argo-workflows.yaml
- dexidp.yaml
24 changes: 24 additions & 0 deletions components/01-secrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ kubectl --namespace nautobot \
> secret-nautobot-redis.yaml
```

```bash
# This secret needs to be synchronized in both namespaces
NAUTOBOT_SSO_SECRET=$(./scripts/pwgen.sh)
for ns in nautobot dex; do
kubectl --namespace $ns \
create secret generic nautobot-sso \
--dry-run=client \
-o yaml \
--type Opaque \
--from-literal=client-secret="$NAUTOBOT_SSO_SECRET" \
> secret-nautobot-sso-$ns.yaml
done
unset NAUTOBOT_SSO_SECRET
```

Let's encrypt them.

```bash
Expand All @@ -77,6 +92,15 @@ kubeseal \
-o yaml \
-f secret-nautobot-redis.yaml \
-w components/01-secrets/encrypted-nautobot-redis.yaml

for ns in nautobot dex; do
kubeseal \
--scope cluster-wide \
--allow-empty-data \
-o yaml \
-f secret-nautobot-sso-$ns.yaml \
-w components/01-secrets/encrypted-nautobot-sso-$ns.yaml
done
```

## Keystone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ data:
SOCIAL_AUTH_OIDC_OIDC_ENDPOINT = "http://dexidp.local"
SOCIAL_AUTH_OIDC_USERNAME_KEY = 'name'
SOCIAL_AUTH_OIDC_KEY = 'nautobot'
SOCIAL_AUTH_OIDC_SECRET = 'verysecret'
SOCIAL_AUTH_OIDC_SECRET = open("/opt/nautobot/dex_client_secret").read()
# The “openid”, “profile” and “email” are requested by default,
# below *adds* scope.
SOCIAL_AUTH_OIDC_SCOPE = ['groups']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ spec:
- name: "nautobot-config"
mountPath: "/opt/nautobot/nautobot_config.py"
subPath: "nautobot_config.py"
- name: "nautobot-dexauth"
mountPath: "/opt/nautobot/dexauth.py"
subPath: "dexauth.py"
readOnly: true
- name: "nautobot-dex-creds"
mountPath: "/opt/nautobot/dex_client_secret"
subPath: client-secret
readOnly: true
containers:
- name: nautobot
tty: true
Expand Down Expand Up @@ -178,6 +186,11 @@ spec:
- name: "nautobot-dexauth"
mountPath: "/opt/nautobot/dexauth.py"
subPath: "dexauth.py"
readOnly: true
- name: "nautobot-dex-creds"
mountPath: "/opt/nautobot/dex_client_secret"
subPath: client-secret
readOnly: true
ports:
- name: "https"
containerPort: 8443
Expand All @@ -196,3 +209,7 @@ spec:
- name: "nautobot-dexauth"
configMap:
name: dexauth
- name: "nautobot-dex-creds"
secret:
secretName: nautobot-sso
optional: false
3 changes: 0 additions & 3 deletions components/13-dexidp/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- namespace.yaml

namespace: dex
helmGlobals:
chartHome: ../../charts/
Expand Down
8 changes: 7 additions & 1 deletion components/13-dexidp/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ config:

staticClients:
- id: nautobot
secret: verysecret
secretEnv: NAUTOBOT_SSO_CLIENT_SECRET
name: "Undercloud Nautobot"
redirectURIs:
- "http://localhost:8000/complete/oidc/"
- "https://nautobot.local/complete/oidc/"

envVars:
- name: NAUTOBOT_SSO_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: nautobot-sso
key: client-secret
ingress:
enabled: true
annotations:
Expand Down
21 changes: 21 additions & 0 deletions scripts/easy-secrets-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ kubectl --namespace nautobot \
--from-literal=redis-password="$(./scripts/pwgen.sh)" \
> secret-nautobot-redis.yaml

NAUTOBOT_SSO_SECRET=$(./scripts/pwgen.sh)
for ns in nautobot dex; do
kubectl --namespace $ns \
create secret generic nautobot-sso \
--dry-run=client \
-o yaml \
--type Opaque \
--from-literal=client-secret="$NAUTOBOT_SSO_SECRET" \
> secret-nautobot-sso-$ns.yaml
done
unset NAUTOBOT_SSO_SECRET

kubectl --namespace openstack \
create secret generic keystone-rabbitmq-password \
--type Opaque \
Expand Down Expand Up @@ -105,6 +117,15 @@ for skrt in $(find . -maxdepth 1 -name "secret-keystone*.yaml" -o -name "secret-
-w "${encskrt}"
done

for ns in nautobot dex; do
kubeseal \
--scope cluster-wide \
--allow-empty-data \
-o yaml \
-f secret-nautobot-sso-$ns.yaml \
-w components/01-secrets/encrypted-nautobot-sso-$ns.yaml
done

cd components/01-secrets/
rm -f kustomization.yaml
kustomize create --autodetect
Expand Down
Loading