Skip to content

feat: add service secrets management API - #623

Open
SergioLangaritaBenitez wants to merge 3 commits into
develfrom
feat-list-secrets
Open

feat: add service secrets management API#623
SergioLangaritaBenitez wants to merge 3 commits into
develfrom
feat-list-secrets

Conversation

@SergioLangaritaBenitez

@SergioLangaritaBenitez SergioLangaritaBenitez commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Fixes # https://github.com/grycap/issue-tracker/issues/447

Description

Adds CRUD endpoints to manage service environment secrets at runtime, without
redeploying the service. Service secrets are stored in Kubernetes Secrets and
injected into service pods; this PR exposes them through the OSCAR API.

Changes

New endpoints under /system/secrets

  • GET /system/secrets — lists the secrets of the accessible services.
    Secret values are only returned for services owned by the caller.
  • GET /system/secrets/{serviceName} — returns the environment secrets of a
    specific service.
  • PUT /system/secrets/{serviceName} — merges the given key-value pairs into
    the service secrets. Keys that do not exist yet are created and keys not
    present in the request are preserved. The reserved refresh_token key cannot
    be modified.

When updating, the service ConfigMap (FDL) is kept in sync: the new secret keys
are added to environment.secrets with empty values, following the convention
that secret values only live in the Kubernetes Secret.

Files

  • pkg/handlers/secrets.go — list, get, and update handlers plus the
    ConfigMap/FDL synchronization logic.
  • pkg/handlers/secrets_test.go — handler tests (10 cases covering
    list/get/update, visibility rules, reserved keys, and empty bodies).
  • pkg/types/secret.go — request/response types (SecretUpdateRequest,
    ServiceSecrets).
  • pkg/utils/secrets.goGetSecret and MergeSecretData helpers.
  • pkg/utils/secrets_test.go — unit tests for the new helpers.
  • main.go — route registration for the three endpoints.
  • docs/api.md, docs/fdl.md — documentation for the new endpoints.
  • pkg/handlers/buckets/{create,list,update}_bucket.go — fix the
    MinIOBucket swagger annotation (utils.MinIOBucket -> types.MinIOBucket)
    so swag init can generate the OpenAPI spec, which was previously failing.

Testing

  • go test ./... passes.
  • swag init -g main.go --outputTypes yaml succeeds and includes the
    /system/secrets endpoints in the generated spec.

Add CRUD endpoints under /system/secrets to manage service environment
secrets at runtime:

- GET /system/secrets lists the secrets of the accessible services, with
  values only returned for services owned by the caller.
- GET /system/secrets/{serviceName} returns the secrets of a specific
  service.
- PUT /system/secrets/{serviceName} merges key-value pairs into the
  service secrets, creating new keys and preserving existing ones.

The update also keeps the service ConfigMap FDL in sync. Fix the
MinIOBucket swagger annotation so swag can generate the OpenAPI spec,
and document the new endpoints.
Adapt the service secrets endpoints to the new per-service routes:
- GET /system/services/{serviceName}/secrets?key=KEY returns the value of a
  single secret key (404 if the key does not exist or is not provided).
- PUT /system/services/{serviceName}/secrets accepts the secrets as a plain
  JSON object in the body and responds 204 No Content on success.
- Remove the GET /system/secrets list endpoint, its handler, and the now
  unused SecretUpdateRequest/ServiceSecrets types.
- Update the swagger annotations, tests, and API documentation accordingly.
@SergioLangaritaBenitez

Copy link
Copy Markdown
Contributor Author

This PR moves the service secrets API under the per-service routes:

  • GET /system/services/{serviceName}/secrets?key=KEY returns the value of a single secret key (404 if the key does not exist or is not provided).
  • PUT /system/services/{serviceName}/secrets takes the secrets as a plain JSON object in the request body and responds with 204 No Content on success. Existing keys are preserved and the reserved refresh_token key cannot be modified.
  • Removed the GET /system/secrets list endpoint, its handler, and the now unused SecretUpdateRequest/ServiceSecrets types.
  • Updated swagger annotations, tests, and the API documentation in docs/api.md and docs/fdl.md.

- Add GET and PUT /system/secrets endpoints that read/write the current
  user's secret (named after auth.FormatUID(uid)) in the user namespace.
- Add GET and PUT /system/services/{serviceName}/secrets endpoints, replacing
  the previous /system/secrets/{serviceName} routes.
- GET returns the value of a single secret key (404 if missing); PUT takes a
  plain JSON object and responds 204 No Content.
- Protect the reserved keys refresh_token, accessKey, secretKey, and oidc_uid.
- Export AccessKey, SecretKey, and OIDCUID constants in the auth package and
  use them across handlers and tests.
- Update swagger annotations, tests, and the API documentation.
@SergioLangaritaBenitez

Copy link
Copy Markdown
Contributor Author

This PR adds the new secrets endpoints and aligns the existing ones with the per-user/per-service model:

  • GET /system/secrets?key=KEY and PUT /system/secrets operate on the current user's secret (named after auth.FormatUID(uid)) in the user namespace.
  • GET /system/services/{serviceName}/secrets?key=KEY and PUT /system/services/{serviceName}/secrets operate on the secrets of a specific service, replacing the previous /system/secrets/{serviceName} routes.
  • GET returns the value of a single secret key (404 if the key or the secret does not exist); PUT accepts a plain JSON object of key-value pairs and responds 204 No Content.
  • The reserved keys refresh_token, accessKey, secretKey, and oidc_uid cannot be modified.
  • Exported AccessKey, SecretKey, and OIDCUID constants in the auth package and used them consistently across handlers and tests.
  • Updated swagger annotations, tests, and the API documentation in docs/api.md.

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.

1 participant