Skip to content

Commit f80b669

Browse files
authored
feat: allow to toggle off v1 services (#770)
Details: * add `revproxy.enableV1Services` and `login.enableV1Services` configuration fields * when v1 services are not active: * do not serve `/api`, `/api/direct`, etc. -> GitLab * do not serve `/api/kg`, etc. -> KG, webhook * do not serve `/ui-server/*` routes related to v1 features * do not login though GitLab * do not logout from GitLab * also, remove routes to `/api/search` (service is not deployed anymore)
1 parent 4c8645e commit f80b669

9 files changed

Lines changed: 371 additions & 203 deletions

File tree

internal/config/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ sessions:
2323
audience: renku
2424
authorizedParty: renku-cli
2525
revproxy:
26+
enableV1Services: true
2627
renkuBaseUrl: "https://renkulab.io"
2728
externalGitlabUrl:
2829
k8sNamespace:
@@ -39,6 +40,7 @@ revproxy:
3940
keycloak:
4041
search:
4142
login:
43+
enableV1Services: true
4244
endpointsBasePath:
4345
renkuBaseURL: "https://renkulab.io"
4446
tokenEncryption:

internal/config/login.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type TokenEncryptionConfig struct {
1111
}
1212

1313
type LoginConfig struct {
14+
EnableV1Services bool
1415
RenkuBaseURL *url.URL
1516
LoginRoutesBasePath string
1617
TokenEncryption TokenEncryptionConfig
@@ -34,6 +35,10 @@ type OIDCClient struct {
3435
}
3536

3637
func (c LoginConfig) Validate(e RunningEnvironment) error {
38+
// Fix the login config when EnableV1Services is false
39+
if !c.EnableV1Services {
40+
delete(c.Providers, "gitlab")
41+
}
3742
if c.TokenEncryption.Enabled && len(c.TokenEncryption.SecretKey) != 32 {
3843
return fmt.Errorf(
3944
"token encryption key has to be 32 bytes long, the provided one is %d long",

internal/config/revproxy.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ type RenkuServicesConfig struct {
1212
DataService *url.URL
1313
Keycloak *url.URL
1414
UIServer *url.URL
15-
Search *url.URL
1615
}
1716

1817
type RevproxyConfig struct {
18+
EnableV1Services bool
1919
RenkuBaseURL *url.URL
2020
ExternalGitlabURL *url.URL
2121
K8sNamespace string
@@ -29,12 +29,7 @@ type CoreSvcConfig struct {
2929
}
3030

3131
func (r *RevproxyConfig) Validate() error {
32-
if r.RenkuServices.KG == nil {
33-
return fmt.Errorf("the proxy config is missing the url to the knowledge graph service")
34-
}
35-
if r.RenkuServices.Webhook == nil {
36-
return fmt.Errorf("the proxy config is missing the url to the webhook service")
37-
}
32+
// Check v2 services first
3833
if r.RenkuServices.DataService == nil {
3934
return fmt.Errorf("the proxy config is missing the url to the data service")
4035
}
@@ -44,11 +39,19 @@ func (r *RevproxyConfig) Validate() error {
4439
if r.RenkuServices.UIServer == nil {
4540
return fmt.Errorf("the proxy config is missing the url to ui-server")
4641
}
47-
if r.RenkuServices.Search == nil {
48-
return fmt.Errorf("the proxy config is missing the url to search")
49-
}
50-
if len(r.RenkuServices.Core.ServiceNames) != len(r.RenkuServices.Core.ServicePaths) {
51-
return fmt.Errorf("the number of core service names and paths do not match")
42+
43+
// Check v1 services if needed
44+
if r.EnableV1Services {
45+
if r.RenkuServices.KG == nil {
46+
return fmt.Errorf("the proxy config is missing the url to the knowledge graph service")
47+
}
48+
if r.RenkuServices.Webhook == nil {
49+
return fmt.Errorf("the proxy config is missing the url to the webhook service")
50+
}
51+
if len(r.RenkuServices.Core.ServiceNames) != len(r.RenkuServices.Core.ServicePaths) {
52+
return fmt.Errorf("the number of core service names and paths do not match")
53+
}
5254
}
55+
5356
return nil
5457
}

internal/config/revproxy_test.go

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func getValidRevproxyConfig(t *testing.T) RevproxyConfig {
1515
require.NoError(t, err)
1616
renkuServicesConfig := getValidRenkuServicesConfig(t)
1717
return RevproxyConfig{
18+
EnableV1Services: true,
1819
RenkuBaseURL: renkuBaseURL,
1920
ExternalGitlabURL: externalGitlabURL,
2021
RenkuServices: renkuServicesConfig,
@@ -32,15 +33,37 @@ func getValidRenkuServicesConfig(t *testing.T) RenkuServicesConfig {
3233
require.NoError(t, err)
3334
uiServerURL, err := url.Parse("http://ui")
3435
require.NoError(t, err)
35-
searchURL, err := url.Parse("http://ui")
36-
require.NoError(t, err)
3736
return RenkuServicesConfig{
3837
KG: kgURL,
3938
Webhook: webhookURL,
4039
DataService: dataServiceURL,
4140
Keycloak: keycloakURL,
4241
UIServer: uiServerURL,
43-
Search: searchURL,
42+
}
43+
}
44+
45+
func getValidV2OnlyRevproxyConfig(t *testing.T) RevproxyConfig {
46+
renkuBaseURL, err := url.Parse("https://renku.example.org")
47+
require.NoError(t, err)
48+
renkuServicesConfig := getValidV2OnlyRenkuServicesConfig(t)
49+
return RevproxyConfig{
50+
EnableV1Services: false,
51+
RenkuBaseURL: renkuBaseURL,
52+
RenkuServices: renkuServicesConfig,
53+
}
54+
}
55+
56+
func getValidV2OnlyRenkuServicesConfig(t *testing.T) RenkuServicesConfig {
57+
dataServiceURL, err := url.Parse("http://data-service")
58+
require.NoError(t, err)
59+
keycloakURL, err := url.Parse("http://keycloak")
60+
require.NoError(t, err)
61+
uiServerURL, err := url.Parse("http://ui")
62+
require.NoError(t, err)
63+
return RenkuServicesConfig{
64+
DataService: dataServiceURL,
65+
Keycloak: keycloakURL,
66+
UIServer: uiServerURL,
4467
}
4568
}
4669

@@ -52,6 +75,21 @@ func TestValidRevproxyConfig(t *testing.T) {
5275
assert.NoError(t, err)
5376
}
5477

78+
func TestValidV2OnlyRevproxyConfig(t *testing.T) {
79+
config := getValidV2OnlyRevproxyConfig(t)
80+
81+
err := config.Validate()
82+
83+
// Check that the v1 service configuration is not provided
84+
assert.Nil(t, config.ExternalGitlabURL)
85+
assert.Empty(t, config.RenkuServices.Core.ServiceNames)
86+
assert.Empty(t, config.RenkuServices.Core.ServicePaths)
87+
assert.Nil(t, config.RenkuServices.KG)
88+
assert.Nil(t, config.RenkuServices.Webhook)
89+
90+
assert.NoError(t, err)
91+
}
92+
5593
func TestInvalidKGURL(t *testing.T) {
5694
config := getValidRevproxyConfig(t)
5795
config.RenkuServices.KG = nil
@@ -97,15 +135,6 @@ func TestInvalidUIServerURL(t *testing.T) {
97135
assert.ErrorContains(t, err, "the proxy config is missing the url to ui-server")
98136
}
99137

100-
func TestInvalidSearchURL(t *testing.T) {
101-
config := getValidRevproxyConfig(t)
102-
config.RenkuServices.Search = nil
103-
104-
err := config.Validate()
105-
106-
assert.ErrorContains(t, err, "the proxy config is missing the url to search")
107-
}
108-
109138
func TestInvalidCoreSvcConfig(t *testing.T) {
110139
config := getValidRevproxyConfig(t)
111140
config.RenkuServices.Core.ServiceNames = []string{"core-svc"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
package login
22

33
var defaultLoginSequence = [...]string{"renku", "gitlab"}
4+
var v2OnlyLoginSequence = [...]string{"renku"}

internal/login/login_server_routes.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (l *LoginServer) GetLogin(c echo.Context, params GetLoginParams) error {
3030
if params.ProviderId != nil && len(*params.ProviderId) > 0 {
3131
loginSequence = *params.ProviderId
3232
} else {
33-
loginSequence = defaultLoginSequence[:]
33+
loginSequence = l.getLoginSequence()
3434
}
3535
session.LoginSequence = loginSequence
3636
return l.nextAuthStep(c, session)
@@ -242,3 +242,11 @@ func (l *LoginServer) nextAuthStep(
242242
l.sessions.Save(c)
243243
return echo.WrapHandler(handler)(c)
244244
}
245+
246+
func (l *LoginServer) getLoginSequence() (loginSequence []string) {
247+
if l.config.EnableV1Services {
248+
return defaultLoginSequence[:]
249+
} else {
250+
return v2OnlyLoginSequence[:]
251+
}
252+
}

internal/login/login_server_routes_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,18 @@ func getTestConfig(loginServerPort int, authServers ...testAuthServer) (config.L
4545
if err != nil {
4646
return config.LoginConfig{}, err
4747
}
48+
49+
// Toggle `EnableV1Services` on if we authenticate with GitLab
50+
enableV1Services := false
51+
for _, auth := range authServers {
52+
if auth.ClientID == "gitlab" {
53+
enableV1Services = true
54+
}
55+
}
56+
4857
testConfig := config.LoginConfig{
49-
RenkuBaseURL: renkuBaseURL,
58+
EnableV1Services: enableV1Services,
59+
RenkuBaseURL: renkuBaseURL,
5060
TokenEncryption: config.TokenEncryptionConfig{
5161
Enabled: true,
5262
SecretKey: "1b195c6329ba7df1c1adf6975c71910d",

0 commit comments

Comments
 (0)