feat: add service secrets management API - #623
Open
SergioLangaritaBenitez wants to merge 3 commits into
Open
Conversation
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.
Contributor
Author
|
This PR moves the service secrets API under the per-service routes:
|
- 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.
Contributor
Author
|
This PR adds the new secrets endpoints and aligns the existing ones with the per-user/per-service model:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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/secretsGET /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 aspecific service.
PUT /system/secrets/{serviceName}— merges the given key-value pairs intothe service secrets. Keys that do not exist yet are created and keys not
present in the request are preserved. The reserved
refresh_tokenkey cannotbe modified.
When updating, the service ConfigMap (FDL) is kept in sync: the new secret keys
are added to
environment.secretswith empty values, following the conventionthat secret values only live in the Kubernetes Secret.
Files
pkg/handlers/secrets.go— list, get, and update handlers plus theConfigMap/FDL synchronization logic.
pkg/handlers/secrets_test.go— handler tests (10 cases coveringlist/get/update, visibility rules, reserved keys, and empty bodies).
pkg/types/secret.go— request/response types (SecretUpdateRequest,ServiceSecrets).pkg/utils/secrets.go—GetSecretandMergeSecretDatahelpers.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 theMinIOBucketswagger annotation (utils.MinIOBucket->types.MinIOBucket)so
swag initcan generate the OpenAPI spec, which was previously failing.Testing
go test ./...passes.swag init -g main.go --outputTypes yamlsucceeds and includes the/system/secretsendpoints in the generated spec.