Skip to content

AUT-11295 Manage workspace secrets via dedicated secrets pipeline - #50

Draft
piotrek-janus wants to merge 8 commits into
masterfrom
feature/secrets-v2
Draft

piotrek-janus wants to merge 8 commits into
masterfrom
feature/secrets-v2

Conversation

@piotrek-janus

Copy link
Copy Markdown
Contributor

Jira task - https://secureauth.atlassian.net/browse/AUT-11295

Release Notes Description (public)

Manage workspace secrets as config-as-code using the dedicated secret system APIs. New --workspace-secrets <workspace> flag on pull, push, and diff operates exclusively on secrets: pull scaffolds env-injected stub files, push reconciles remote secrets from local definitions (create/update, delete with --prune), and diff compares local definitions against the remote workspace. Secret values are never stored in the repository — each secret file references an environment variable resolved at push time.

Implementation details (internal)

Alternative to #30 (same Jira). Instead of threading a Patch/Ext envelope through every Source/Storage/Validator/diff signature, secrets get a self-contained vertical slice; the existing config pipeline is untouched.

  • internal/cac/secrets: local model, pure plan computation (ComputePlan → create/update/delete sets), and DirStore for workspaces/<wid>/secrets/*.yaml. ListIDs reads raw YAML (no env vars needed, used by pull/diff); List renders {{ env }} templates and rejects empty values before any API call (used by push).
  • internal/cac/client/secrets_api.go: SecretsAPIStore over the system Secrets CRUD API.
  • Stub format: value: '{{ env "CAC_SECRET_<ID>" }}' — single-quoted so files parse as plain YAML while remaining valid Go templates. pull never overwrites existing secret files.
  • --workspace-secrets is mutually exclusive with --workspace/--tenant/--filter; push --method and diff --source/--target are validated in RunE so they stay required for config mode only.
  • Secret values never appear in logs, plan summaries, or dry-run output — IDs only. push --dry-run prints exactly the plan a real push would apply.

Information for QA

  • Is QA testing required?
  • Does PR contain unit tests?
  • Should QA create E2E tests for the change?

Additional QA Procedures (Optional)

Suggested manual flow against a dev tenant: pull --workspace-secrets <wid> (stubs created, re-run skips), set CAC_SECRET_* env vars, push --workspace-secrets <wid> --dry-run (plan lists IDs only), real push, diff --workspace-secrets <wid>, and push --prune after deleting a local file.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate issues can break secret pushes, API requests, output handling, and collision-safe storage.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity

Open (3)
What changed in this PR

Adds config-as-code workspace-secret management using environment-backed YAML stubs and dedicated Secrets APIs.

Changes:

  • Adds secret planning, filesystem storage, and API reconciliation.
  • Adds --workspace-secrets support to pull, push, and diff.
  • Adds documentation, unit tests, and mock API coverage.

Review findings:

  • Moderate (1 vote): cmd/diff.go:57 reports both --source and --target as missing when only one is unset.
  • Moderate (1 vote): cmd/push.go:165 ignores --out during secrets dry runs.
  • Moderate (1 vote): internal/cac/client/secrets_api.go:44 omits required tenant_id from create requests.
  • Moderate (1 vote): internal/cac/client/secrets_api.go:54 omits required tenant_id from update requests.
  • Moderate (2 votes): internal/cac/secrets/dir_store.go:148-149 checks normalized paths rather than IDs, causing shadowing and filename collisions.
  • Critical (2 votes): internal/cac/secrets/dir_store.go:71,74,151,158,160 renders lower-precedence duplicates before skipping them, allowing irrelevant missing environment variables to fail pushes.
  • Moderate (1 vote): internal/cac/secrets/dir_store.go:158 generates colliding environment-variable names for distinct secret IDs.
  • Moderate (3 votes): internal/cac/secrets/secrets.go:102 uses a lossy environment-variable mapping that aliases distinct IDs.
  • Moderate (1 vote): internal/cac/secrets/secrets.go:94 normalizes distinct IDs to identical filenames, preventing all stubs from being created.
File Description
README.md Documents workspace-secret workflows.
internal/​cac/​secrets/​secrets.go Defines secret models, plans, and naming helpers.
internal/​cac/​secrets/​secrets_test.go Tests planning and naming behavior.
internal/​cac/​secrets/​dir_store.go Reads definitions and writes secret stubs.
internal/​cac/​secrets/​dir_store_test.go Tests directory storage behavior.
internal/​cac/​client/​secrets_api.go Implements Secrets API operations.
internal/​cac/​client/​secrets_api_test.go Tests Secrets API integration.
internal/​cac/​client/​mock_server_test.go Adds mock secret endpoints.
internal/​cac/​app.go Exposes the Secrets API store.
cmd/​root.go Adds the workspace-secrets flag.
cmd/​push.go Implements secret reconciliation, pruning, and dry runs.
cmd/​pull.go Implements secret stub generation.
cmd/​flags.go Removes the obsolete required-flag helper.
cmd/​diff.go Implements secret ID comparison.
cmd/​diff_secrets_test.go Tests secret diff reporting.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +71 to +74
err := d.walk(wid, func(path string) error {
var s Secret

bts, err := templates.New(path).Render()
Comment on lines +148 to +153
for _, id := range ids {
file := filepath.Join(path, NormalizeFileName(id)+".yaml")

if _, err = os.Stat(file); err == nil {
skipped = append(skipped, id)
continue
Comment on lines +102 to +103
func EnvVarName(id string) string {
return "CAC_SECRET_" + nonEnv.ReplaceAllString(strings.ToUpper(id), "_")

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants