Skip to content

feat(usagedb): add authentication to UsageDBConfig - #34

Open
liuxu623 wants to merge 1 commit into
kai-scheduler:mainfrom
liuxu623:feat/usagedb-auth
Open

liuxu623 wants to merge 1 commit into
kai-scheduler:mainfrom
liuxu623:feat/usagedb-auth

Conversation

@liuxu623

Copy link
Copy Markdown

Description

Adds Auth to usagedb.UsageDBConfig, so the scheduler's usage database client can authenticate to an external Prometheus-compatible store.

usageDBConfig:
  clientType: prometheus
  connectionString: https://metrics.example.com/prometheus
  auth:
    basicAuth:
      username: {name: kai-usage-db, key: username}
      password: {name: kai-usage-db, key: password}
    # or, instead of basicAuth:
    authorization:
      type: Bearer
      credentials: {name: kai-usage-db, key: token}
  • basicAuth and authorization are mutually exclusive. The shape follows the Prometheus Operator.
  • Each value has one source: a Secret key (corev1.SecretKeySelector) or a file (usernameFile, passwordFile, credentialsFile).
  • Auth.Validate() checks that the two forms are not combined, that each value has exactly one source, that a Secret reference has a name and a key, and that Basic is not used as an authorization type.
  • UsageDBConfig.DeepCopy copies Auth. The SchedulingShard CRD is regenerated.

Why both a Secret key and a file: the same type is used on the SchedulingShard and in the scheduler configuration. On a shard the user names a Secret key. The operator can mount it and put the file path in the scheduler configuration, so no credential reaches the ConfigMap. A scheduler that runs without the operator sets the file paths directly.

This PR adds the types only. The operator and scheduler changes follow in KAI-Scheduler once this is released.

Related Issues

Refs kai-scheduler/KAI-Scheduler#2639

Checklist

  • Self-reviewed
  • Added/updated tests (if needed)
  • Updated documentation (if needed): GoDoc on the new types. The user docs live in KAI-Scheduler and come with the follow-up.
  • Added a changelog fragment via make changelog (or applied the skip-changelog label).

Breaking Changes

None. auth is optional, and a config without it behaves as before.

Additional Notes

  • make validate and go test ./... pass.
  • The fragment was written by hand in the format make changelog produces: the target fails silently when .changes/unreleased/ does not exist, and it runs backticks in BODY as commands.

🤖 Generated with Claude Code

The usage database client has no way to authenticate: it is built from an
address alone, a credential in connectionString is plain text in the
SchedulingShard and in the scheduler ConfigMap, and connectionStringEnvVar
names a variable the operator gives no way to set.

Add UsageDBConfig.Auth with two mutually exclusive forms, in the shape
the Prometheus Operator uses:

- basicAuth: a username and an optional password
- authorization: a type (default Bearer) and credentials

Each value has one source, a Secret key or a file. On a SchedulingShard
the source is a Secret key; the operator can mount it and give the
scheduler the file path, so no credential reaches the scheduler
configuration. A scheduler that runs without the operator sets the file
paths directly.

Auth.Validate checks that the two forms are not combined, that each value
has exactly one source, that a Secret reference has a name and a key, and
that "Basic" is not used as an authorization type.

Refs kai-scheduler/KAI-Scheduler#2639

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: liuxu <liuxu623@gmail.com>
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