Skip to content

Commit b9060a3

Browse files
committed
RHINENG-19161: setup Kessel service client
1 parent 31dce21 commit b9060a3

5 files changed

Lines changed: 72 additions & 10 deletions

File tree

base/utils/config.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type coreConfig struct {
9393
KesselAuthClientID string
9494
KesselAuthClientSecret string
9595
KesselAuthOIDCIssuer string
96+
RbacURL string
9697

9798
// prometheus pushgateway
9899
PrometheusPushGateway string
@@ -266,6 +267,8 @@ func initServicesFromClowder() {
266267
}
267268
case "rbac":
268269
CoreCfg.RbacAddress = (*Endpoint)(&endpoint).buildURL()
270+
case "rbac-service":
271+
CoreCfg.RbacURL = (*Endpoint)(&endpoint).buildURL()
269272
}
270273
}
271274

@@ -337,13 +340,14 @@ func initLoggerFromEnv() {
337340
}
338341

339342
func initKesselFromEnv() {
340-
CoreCfg.KesselEnabled = GetBoolEnvOrDefault("KESSEL_ENABLED", false)
341-
CoreCfg.KesselURL = Getenv("KESSEL_URL", "")
342-
CoreCfg.KesselAuthEnabled = GetBoolEnvOrDefault("KESSEL_AUTH_ENABLED", false)
343-
CoreCfg.KesselInsecure = GetBoolEnvOrDefault("KESSEL_INSECURE", true)
344-
CoreCfg.KesselAuthClientID = Getenv("KESSEL_AUTH_CLIENT_ID", "")
345-
CoreCfg.KesselAuthClientSecret = Getenv("KESSEL_AUTH_CLIENT_SECRET", "")
346-
CoreCfg.KesselAuthOIDCIssuer = Getenv("KESSEL_AUTH_OIDC_ISSUER", "")
343+
CoreCfg.KesselEnabled = GetBoolEnvOrDefault("KESSEL_ENABLED", CoreCfg.KesselEnabled)
344+
CoreCfg.KesselURL = Getenv("KESSEL_URL", CoreCfg.KesselURL)
345+
CoreCfg.KesselAuthEnabled = GetBoolEnvOrDefault("KESSEL_AUTH_ENABLED", CoreCfg.KesselAuthEnabled)
346+
CoreCfg.KesselInsecure = GetBoolEnvOrDefault("KESSEL_INSECURE", CoreCfg.KesselInsecure)
347+
CoreCfg.KesselAuthClientID = Getenv("KESSEL_AUTH_CLIENT_ID", CoreCfg.KesselAuthClientID)
348+
CoreCfg.KesselAuthClientSecret = Getenv("KESSEL_AUTH_CLIENT_SECRET", CoreCfg.KesselAuthClientSecret)
349+
CoreCfg.KesselAuthOIDCIssuer = Getenv("KESSEL_AUTH_OIDC_ISSUER", CoreCfg.KesselAuthOIDCIssuer)
350+
CoreCfg.RbacURL = Getenv("RBAC_URL", CoreCfg.RbacURL)
347351
}
348352

349353
// PrintClowderParams Print Clowder params to export environment variables.

conf/test.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ LIMIT_PAGE_SIZE=false
1313
POD_CONFIG=label=upload;vmaas_call_max_retries=100;baseline_change_eval=false;update_users;update_db_config;use_testing_db
1414

1515
KESSEL_URL=platform:9005
16+
KESSEL_INSECURE=true

deploy/clowdapp.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ objects:
107107
- {name: RATELIMIT, value: '${RATELIMIT}'}
108108
- {name: LIMIT_PAGE_SIZE, value: '${LIMIT_PAGE_SIZE}'}
109109
- {name: POD_CONFIG, value: '${MANAGER_CONFIG}'}
110+
- {name: KESSEL_ENABLED, value: '${KESSEL_ENABLED}'}
111+
- {name: KESSEL_URL, value: '${KESSEL_URL}'}
112+
- {name: KESSEL_AUTH_ENABLED, value: '${KESSEL_AUTH_ENABLED}'}
113+
- {name: KESSEL_AUTH_OIDC_ISSUER, value: '${KESSEL_AUTH_OIDC_ISSUER}'}
114+
- {name: KESSEL_INSECURE, value: '${KESSEL_INSECURE}'}
115+
- {name: KESSEL_AUTH_CLIENT_ID, valueFrom: {secretKeyRef: {name: kessel-service-client, key: id}}}
116+
- {name: KESSEL_AUTH_CLIENT_SECRET, valueFrom: {secretKeyRef: {name: kessel-service-client, key: secret}}}
110117

111118
resources:
112119
limits: {cpu: '${CPU_LIMIT_MANAGER}', memory: '${MEM_LIMIT_MANAGER}'}
@@ -728,3 +735,10 @@ parameters:
728735
- {name: MEM_REQUEST_FLOORIST, value: 2Gi}
729736
- {name: CPU_LIMIT_FLOORIST, value: 500m}
730737
- {name: MEM_LIMIT_FLOORIST, value: 4Gi}
738+
739+
# Kessel
740+
- {name: KESSEL_ENABLED, value: 'false'}
741+
- name: KESSEL_URL
742+
- name: KESSEL_AUTH_ENABLED
743+
- name: KESSEL_AUTH_OIDC_ISSUER
744+
- name: KESSEL_INSECURE

manager/middlewares/kessel.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ import (
2121
type ListObjectStreamingClient = grpc.ServerStreamingClient[kesselAPIv2.StreamedListObjectsResponse]
2222

2323
func setupClient() (*kesselClientV2.InventoryClient, error) {
24-
// TODO: use secure credentials
2524
options := []func(*kesselClientCommon.Config){
2625
kesselClientCommon.WithgRPCUrl(utils.CoreCfg.KesselURL),
2726
kesselClientCommon.WithTLSInsecure(utils.CoreCfg.KesselInsecure),
2827
}
28+
29+
if utils.CoreCfg.KesselAuthEnabled {
30+
options = append(options, kesselClientCommon.WithAuthEnabled(
31+
utils.CoreCfg.KesselAuthClientID, utils.CoreCfg.KesselAuthClientSecret, utils.CoreCfg.KesselAuthOIDCIssuer,
32+
))
33+
}
34+
2935
return kesselClientV2.New(kesselClientCommon.NewConfig(options...))
3036
}
3137

manager/middlewares/kessel_test.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,45 @@ import (
1616
"github.com/stretchr/testify/assert"
1717
)
1818

19-
func TestSetupClient(_ *testing.T) {
20-
// TODO: implement test after client setup is added
19+
func TestSetupClient(t *testing.T) {
20+
originalKesselInsecure := utils.CoreCfg.KesselInsecure
21+
originalKesselAuthEnabled := utils.CoreCfg.KesselAuthEnabled
22+
originalKesselAuthClientID := utils.CoreCfg.KesselAuthClientID
23+
originalKesselAuthClientSecret := utils.CoreCfg.KesselAuthClientSecret
24+
25+
// insecure TLS and no auth
26+
utils.CoreCfg.KesselInsecure = true
27+
utils.CoreCfg.KesselAuthEnabled = false
28+
client, err := setupClient()
29+
assert.NoError(t, err)
30+
assert.NotNil(t, client)
31+
32+
// secure TLS and no auth
33+
utils.CoreCfg.KesselInsecure = false
34+
client, err = setupClient()
35+
assert.NoError(t, err)
36+
assert.NotNil(t, client)
37+
38+
// insecure TLS and auth
39+
utils.CoreCfg.KesselInsecure = true
40+
utils.CoreCfg.KesselAuthEnabled = true
41+
utils.CoreCfg.KesselAuthClientID = "test-client-id"
42+
utils.CoreCfg.KesselAuthClientSecret = "test-client-secret"
43+
client, err = setupClient()
44+
assert.NoError(t, err)
45+
assert.NotNil(t, client)
46+
47+
// secure TLS and auth
48+
utils.CoreCfg.KesselInsecure = false
49+
client, err = setupClient()
50+
assert.NoError(t, err)
51+
assert.NotNil(t, client)
52+
53+
// cleanup
54+
utils.CoreCfg.KesselInsecure = originalKesselInsecure
55+
utils.CoreCfg.KesselAuthEnabled = originalKesselAuthEnabled
56+
utils.CoreCfg.KesselAuthClientID = originalKesselAuthClientID
57+
utils.CoreCfg.KesselAuthClientSecret = originalKesselAuthClientSecret
2158
}
2259

2360
func TestBuildRequest(t *testing.T) {

0 commit comments

Comments
 (0)