Skip to content

Commit

Permalink
Support disable user creating for OAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
l0kix2 committed Jan 10, 2025
1 parent 40ddc1b commit 5f32643
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 12 deletions.
2 changes: 2 additions & 0 deletions api/v1/ytsaurus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ type OauthServiceSpec struct {
//+kubebuilder:default:=false
Secure bool `json:"secure,omitempty"`
UserInfo OauthUserInfoHandlerSpec `json:"userInfoHandler,omitempty"`
// If DisableUserCreation is set, proxies will NOT create non-existing users with OAuth authentication.
DisableUserCreation *bool `json:"disableUserCreation,omitempty"`
}

type HealthcheckProbeParams struct {
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14893,6 +14893,10 @@ spec:
type: object
oauthService:
properties:
disableUserCreation:
description: If DisableUserCreation is set, proxies will NOT create
non-existing users with O
type: boolean
host:
minLength: 1
type: string
Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ _Appears in:_
| `port` _integer_ | | 80 | |
| `secure` _boolean_ | | false | |
| `userInfoHandler` _[OauthUserInfoHandlerSpec](#oauthuserinfohandlerspec)_ | | | |
| `disableUserCreation` _boolean_ | If DisableUserCreation is set, proxies will NOT create non-existing users with OAuth authentication. | | |


#### OauthUserInfoHandlerSpec
Expand Down
2 changes: 2 additions & 0 deletions pkg/ytconfig/canondata/TestGetHTTPProxyConfig/test.canondata
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@
];
};
"oauth_cookie_authenticator"={
"create_user_if_not_exists"=%false;
};
"oauth_token_authenticator"={
"create_user_if_not_exists"=%false;
};
"require_authentication"=%true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
];
};
"oauth_token_authenticator"={
"create_user_if_not_exists"=%false;
};
"require_authentication"=%true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"http_controller_mappings"={
"*"=chyt;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
"superservice1.some.domain"=superservice1;
"superservice3.some.domain"=superservice3;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
"*"=chyt;
"jupyt.some.domain"=jupyt;
};
}
}
30 changes: 23 additions & 7 deletions pkg/ytconfig/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,17 @@ func (g *Generator) getRPCProxyConfigImpl(spec *ytv1.RPCProxiesSpec) (RPCProxySe

g.fillCommonService(&c.CommonServer, &spec.InstanceSpec)

if g.ytsaurus.Spec.OauthService != nil {
c.OauthService = ptr.To(getOauthService(*g.ytsaurus.Spec.OauthService))
oauthService := g.ytsaurus.Spec.OauthService
if oauthService != nil {
c.OauthService = ptr.To(getOauthService(*oauthService))
c.CypressUserManager = CypressUserManager{}
c.OauthTokenAuthenticator = &OauthTokenAuthenticator{}
var createUserIfNotExist *bool
if oauthService.DisableUserCreation != nil {
createUserIfNotExist = ptr.To(!*oauthService.DisableUserCreation)
}
c.OauthTokenAuthenticator = &OauthTokenAuthenticator{
CreateUserIfNotExists: createUserIfNotExist,
}
c.RequireAuthentication = ptr.To(true)
}

Expand Down Expand Up @@ -670,10 +677,19 @@ func (g *Generator) getHTTPProxyConfigImpl(spec *ytv1.HTTPProxiesSpec) (HTTPProx
g.fillCommonService(&c.CommonServer, &spec.InstanceSpec)
g.fillBusServer(&c.CommonServer, spec.NativeTransport)

if g.ytsaurus.Spec.OauthService != nil {
c.Auth.OauthService = ptr.To(getOauthService(*g.ytsaurus.Spec.OauthService))
c.Auth.OauthCookieAuthenticator = &OauthCookieAuthenticator{}
c.Auth.OauthTokenAuthenticator = &OauthTokenAuthenticator{}
oauthService := g.ytsaurus.Spec.OauthService
if oauthService != nil {
c.Auth.OauthService = ptr.To(getOauthService(*oauthService))
var createUserIfNotExist *bool
if oauthService.DisableUserCreation != nil {
createUserIfNotExist = ptr.To(!*oauthService.DisableUserCreation)
}
c.Auth.OauthCookieAuthenticator = &OauthCookieAuthenticator{
CreateUserIfNotExists: createUserIfNotExist,
}
c.Auth.OauthTokenAuthenticator = &OauthTokenAuthenticator{
CreateUserIfNotExists: createUserIfNotExist,
}
}

return c, nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/ytconfig/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts"

"k8s.io/utils/ptr"
Expand Down Expand Up @@ -597,6 +598,7 @@ func withOauthSpec(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus {
},
},
},
DisableUserCreation: ptr.To(true),
}
return ytsaurus
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/ytconfig/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ type LoginTransformation struct {
Replacement string `yson:"replacement,omitempty"`
}

type OauthCookieAuthenticator struct{}
type OauthTokenAuthenticator struct{}
type OauthCookieAuthenticator struct {
CreateUserIfNotExists *bool `yson:"create_user_if_not_exists,omitempty"`
}
type OauthTokenAuthenticator struct {
CreateUserIfNotExists *bool `yson:"create_user_if_not_exists,omitempty"`
}

type Coordinator struct {
Enable bool `yson:"enable"`
Expand Down
4 changes: 4 additions & 0 deletions ytop-chart/templates/crds/ytsaurus.cluster.ytsaurus.tech.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14904,6 +14904,10 @@ spec:
type: object
oauthService:
properties:
disableUserCreation:
description: If DisableUserCreation is set, proxies will NOT create
non-existing users with O
type: boolean
host:
minLength: 1
type: string
Expand Down

0 comments on commit 5f32643

Please sign in to comment.