Skip to content

Commit 95702fe

Browse files
authored
Merge pull request #250 from projectsyn/feat/vault-url
Add `vault.addr` and `vault.loginMethod` to the metadata discovery endpoint
2 parents e1f4deb + 85d7409 commit 95702fe

6 files changed

Lines changed: 128 additions & 80 deletions

File tree

docs/modules/ROOT/pages/references/configuration.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ It's returned on the discovery URI and will be picked up by Commodore
3232
It's returned on the discovery URI and will be picked up by Commodore
3333
|Empty
3434

35+
|VAULT_ADDR
36+
|The URI of the Vault instance associated with the Lieutenant instance.
37+
If not empty, it's returned on the discovery URI and can be picked up by client tooling.
38+
|Empty
39+
40+
|VAULT_LOGIN_METHOD
41+
|The login method to use for the Vault instance associated with the Lieutenant instance.
42+
If not empty, it's returned on the discovery URI and can be picked up by client tooling.
43+
|Empty
44+
3545
|K8S_AUTH_CLIENT_CACHE_SIZE
3646
|For each new API client (identified by the auth token), a Kubernetes client will be instantiated to pass through the request with the same token, which usually takes 2 seconds.
3747
The K8s client instance will be cached for subsequent API calls and this setting controls how many instances to keep in memory.

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ func main() {
2626
Namespace: os.Getenv("NAMESPACE"),
2727
OidcDiscoveryURL: os.Getenv("OIDC_DISCOVERY_URL"),
2828
OidcCLientID: os.Getenv("OIDC_CLIENT_ID"),
29+
VaultAddr: os.Getenv("VAULT_ADDR"),
30+
VaultLoginMethod: os.Getenv("VAULT_LOGIN_METHOD"),
2931
}
3032

3133
e, err := service.NewAPIServer(conf)

openapi.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ components:
3333
description: >
3434
A unique object identifier string. Automatically generated by the API on creation (in the form
3535
"<letter>-<adjective>-<noun>-<digits>" where all letters are lowercase, max 63 characters in total).
36+
VaultConfig:
37+
type: object
38+
required:
39+
- addr
40+
properties:
41+
addr:
42+
type: string
43+
format: uri-template
44+
loginMethod:
45+
type: string
3646
OIDCConfig:
3747
type: object
3848
required:
@@ -53,6 +63,8 @@ components:
5363
type: string
5464
oidc:
5565
$ref: '#/components/schemas/OIDCConfig'
66+
vault:
67+
$ref: '#/components/schemas/VaultConfig'
5668
TenantProperties:
5769
type: object
5870
description: |-

pkg/api/openapi.go

Lines changed: 87 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/service/api_service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type APIConfig struct {
3636

3737
OidcDiscoveryURL string
3838
OidcCLientID string
39+
40+
VaultAddr string
41+
VaultLoginMethod string
3942
}
4043

4144
// APIContext is a custom echo context
@@ -81,6 +84,14 @@ func NewAPIServer(conf APIConfig, k8sMiddleware ...KubernetesAuth) (*echo.Echo,
8184
DiscoveryUrl: conf.OidcDiscoveryURL,
8285
}
8386
}
87+
if conf.VaultAddr != "" {
88+
apiImpl.metadata.Vault = &api.VaultConfig{
89+
Addr: conf.VaultAddr,
90+
}
91+
if conf.VaultLoginMethod != "" {
92+
apiImpl.metadata.Vault.LoginMethod = &conf.VaultLoginMethod
93+
}
94+
}
8495

8596
e := echo.New()
8697
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{

pkg/service/api_service_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ func rawSetupTest(t *testing.T, obj ...client.Object) (*echo.Echo, client.Client
260260
Namespace: "default",
261261
OidcDiscoveryURL: "https://idp.example.com/.well-known/openid-configuration",
262262
OidcCLientID: "lieutenant",
263+
VaultAddr: "https://vault.example.com/",
264+
VaultLoginMethod: "oidc",
263265
}
264266
e, err := NewAPIServer(conf, testMiddleWare)
265267
assert.NoError(t, err)
@@ -307,4 +309,8 @@ func TestDiscovery(t *testing.T) {
307309
require.NotNil(t, metadata.Oidc)
308310
assert.Equal(t, "lieutenant", metadata.Oidc.ClientId)
309311
assert.Equal(t, "https://idp.example.com/.well-known/openid-configuration", metadata.Oidc.DiscoveryUrl)
312+
require.NotNil(t, metadata.Vault)
313+
assert.Equal(t, "https://vault.example.com/", metadata.Vault.Addr)
314+
require.NotNil(t, metadata.Vault.LoginMethod)
315+
assert.Equal(t, "oidc", *metadata.Vault.LoginMethod)
310316
}

0 commit comments

Comments
 (0)