-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add lf-staff/lf-contractor LDAP → OpenFGA global team sync script #45
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
Open
emsearcy
wants to merge
13
commits into
main
Choose a base branch
from
feat/LFXV2-1480-global-group-sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+555
−1
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
16eb310
feat: add lf-staff/lf-contractor LDAP → OpenFGA global team sync script
emsearcy af86915
feat: add context deadline, KUBECTL_CONTEXT support, and CronJob hist…
emsearcy e8f5e83
fix: strip auth0| prefix when building FGA member map; preallocate di…
emsearcy e7a66f8
fix: bound token expiry refresh skew to avoid negative window
emsearcy 566c460
fix: drop response bodies from error paths; filter to auth0| subjects…
emsearcy 535d73c
Merge branch 'main' into feat/LFXV2-1480-global-group-sync
emsearcy 6c17ed7
fix: include OpenFGA response body in errors; handle ReadAll errors
emsearcy ed93c98
chore: add Datadog log annotation to sync-global-groups CronJob
emsearcy bffd7fb
chore: add tags.datadoghq.com/service pod label to CronJob
emsearcy 3a3bbde
fix: remove redundant "; skipping" suffix from skipping user error me…
emsearcy 8d93628
chore: align CronJob Go image to go.mod toolchain version
emsearcy b8bcbce
fix: resolve golangci-lint and cspell issues in sync_global_groups
emsearcy 1b33e90
fix: remove defer cancel to satisfy exitAfterDefer gocritic lint rule
emsearcy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,8 @@ | |
| "unmarshals", | ||
| "uids", | ||
| "tracecontext", | ||
| "GOTOOLCHAIN" | ||
| "GOTOOLCHAIN", | ||
| "datadoghq" | ||
| ], | ||
| "overrides": [ | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Copyright The Linux Foundation and each contributor to LFX. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| # cronjob.yaml runs the sync_global_groups script on a schedule inside the | ||
| # cluster. Before applying: | ||
| # 1. Run deploy-configmap.sh to push the latest script as a ConfigMap. | ||
| # 2. Replace all REPLACE_ME values with environment-specific values. | ||
| # 3. Create the fga-sync-global-groups-client-secrets-ad-hoc Secret with | ||
| # client_id and client_secret keys. | ||
| # | ||
| # Apply with: kubectl apply -f cronjob.yaml -n lfx | ||
| apiVersion: batch/v1 | ||
| kind: CronJob | ||
| metadata: | ||
| name: sync-global-groups-ad-hoc | ||
| namespace: lfx | ||
| spec: | ||
| schedule: "*/10 * * * *" # Every 10 minutes. | ||
| concurrencyPolicy: Forbid | ||
| successfulJobsHistoryLimit: 3 | ||
| failedJobsHistoryLimit: 3 | ||
| jobTemplate: | ||
| spec: | ||
| ttlSecondsAfterFinished: 3600 | ||
| backoffLimit: 0 | ||
| template: | ||
| metadata: | ||
| labels: | ||
| tags.datadoghq.com/service: lfx-v2-fga-sync | ||
| annotations: | ||
| ad.datadoghq.com/sync.logs: '[{"service": "lfx-v2-fga-sync", "source": "go"}]' | ||
| spec: | ||
| restartPolicy: Never | ||
| volumes: | ||
| - name: script | ||
| configMap: | ||
| name: sync-global-groups-ad-hoc | ||
| containers: | ||
| - name: sync | ||
| image: golang:1.24-alpine | ||
| command: | ||
| - go | ||
| - run | ||
| - /script/main.go | ||
| volumeMounts: | ||
| - name: script | ||
| mountPath: /script | ||
| env: | ||
| - name: CLIENT_ID | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: fga-sync-global-groups-client-secrets-ad-hoc | ||
| key: client_id | ||
| - name: CLIENT_SECRET | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: fga-sync-global-groups-client-secrets-ad-hoc | ||
| key: client_secret | ||
| - name: LDAP_REST_PROXY | ||
| value: "REPLACE_ME" # e.g. https://ldap-rest-proxy.example.com | ||
| - name: OAUTH_TOKEN_ENDPOINT | ||
| value: "REPLACE_ME" # e.g. https://auth.example.com/oauth/token | ||
| - name: OPENFGA_API_URL | ||
| value: "REPLACE_ME" # e.g. http://lfx-platform-openfga.lfx.svc.cluster.local:8080 | ||
| - name: OPENFGA_STORE_ID | ||
| value: "REPLACE_ME" # OpenFGA store ID | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright The Linux Foundation and each contributor to LFX. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| # deploy-configmap.sh wraps scripts/sync_global_groups/main.go as a Kubernetes | ||
| # ConfigMap and applies it to the cluster. The ConfigMap is intended for use | ||
| # with the accompanying cronjob.yaml. | ||
| # | ||
| # Usage: ./deploy-configmap.sh [namespace] | ||
| # namespace Target Kubernetes namespace (default: lfx) | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| NAMESPACE="${1:-lfx}" | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| SCRIPT_FILE="${SCRIPT_DIR}/main.go" | ||
| CONFIGMAP_NAME="sync-global-groups-ad-hoc" | ||
|
|
||
| # Support KUBECTL_CONTEXT env var to select a kubeconfig context. | ||
| KUBECTL_ARGS=() | ||
| if [[ -n "${KUBECTL_CONTEXT:-}" ]]; then | ||
| KUBECTL_ARGS+=(--context "${KUBECTL_CONTEXT}") | ||
| fi | ||
|
|
||
| echo "Deploying ConfigMap '${CONFIGMAP_NAME}' to namespace '${NAMESPACE}'..." | ||
|
|
||
| kubectl "${KUBECTL_ARGS[@]}" create configmap "${CONFIGMAP_NAME}" \ | ||
| --from-file=main.go="${SCRIPT_FILE}" \ | ||
| --namespace="${NAMESPACE}" \ | ||
| --dry-run=client -o yaml \ | ||
| | kubectl "${KUBECTL_ARGS[@]}" apply -f - | ||
|
|
||
| echo "Done." |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cronjob.yaml hard-codes
metadata.namespace: lfxwhile the instructions also suggest applying with-n ...and deploy-configmap.sh allows an arbitrary namespace. Hard-coding the namespace makes it easy to accidentally deploy into the wrong namespace when testing; consider removingmetadata.namespaceso the kubectl context/-nflag controls the target namespace consistently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional — this manifest is prod-only; the namespace is not expected to vary.