Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bearer cookie name configurable #25

Merged
merged 2 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ rebalance_timer: 15s
```
| Parameter | Type | Default value | Description |
|-------------------|------------|---------------|----------------------------------------------------------------------------------------------------|
| `bearer_cookie_name`| `string` | `Bearer` | The name of the cookie holding bearer token. |
| `redirect.url` | `string` | | URL to redirect users going through the OAuth flow |
| `listen_address` | `string` | | The address that the app is listening on. |
| `logger.level` | `string` | `debug` | Logging level.<br/>Possible values: `debug`, `info`, `warn`, `error`, `dpanic`, `panic`, `fatal`. |
Expand Down
15 changes: 7 additions & 8 deletions auth/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ type Authenticator struct {

// Config for authenticator handler.
type Config struct {
Bearer *bearer.Config
Oauth map[string]*ServiceOauth
TLSEnabled bool
Host string
RedirectURL string
Bearer *bearer.Config
BearerCookieName string
Oauth map[string]*ServiceOauth
TLSEnabled bool
Host string
RedirectURL string
}

// New creates authenticator using config.
Expand Down Expand Up @@ -104,10 +105,8 @@ func (u *Authenticator) Callback(w http.ResponseWriter, r *http.Request) {
return
}

w.Header().Set("Authorization", "Bearer "+strToken)

http.SetCookie(w, &http.Cookie{
Name: "Bearer",
Name: u.config.BearerCookieName,
Value: strToken,
MaxAge: 600,
})
Expand Down
13 changes: 9 additions & 4 deletions cmd/neofs-oauthz/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func (a *app) initAuthCfg(key *keys.PrivateKey) {
if len(listenAddress) == 0 {
listenAddress = defaultListenAddress
}
bearerCookieName := a.cfg.GetString(cfgBearerCookieName)
if len(bearerCookieName) == 0 {
bearerCookieName = defaultBearerCookieName
}

a.authCfg = &auth.Config{
Bearer: &bearer.Config{
Expand All @@ -216,10 +220,11 @@ func (a *app) initAuthCfg(key *keys.PrivateKey) {
ContainerID: containerID,
LifeTime: lifetime,
},
Oauth: make(map[string]*auth.ServiceOauth),
TLSEnabled: a.cfg.GetString(cfgTLSCertificate) != "" || a.cfg.GetString(cfgTLSKey) != "",
Host: listenAddress,
RedirectURL: a.cfg.GetString(cfgRedirectURL),
BearerCookieName: bearerCookieName,
Oauth: make(map[string]*auth.ServiceOauth),
TLSEnabled: a.cfg.GetString(cfgTLSCertificate) != "" || a.cfg.GetString(cfgTLSKey) != "",
Host: listenAddress,
RedirectURL: a.cfg.GetString(cfgRedirectURL),
}

redirectURLCallback := fmt.Sprintf(callbackURLFmt, a.authCfg.RedirectURL)
Expand Down
12 changes: 6 additions & 6 deletions cmd/neofs-oauthz/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
)

const (
defaultRebalanceTimer = 15 * time.Second
defaultRequestTimeout = 15 * time.Second
defaultConnectTimeout = 30 * time.Second
defaultBearerLifetime = 30
defaultBearerCookieName = "Bearer"
defaultBearerLifetime = 30
defaultConnectTimeout = 30 * time.Second
defaultRebalanceTimer = 15 * time.Second
defaultRequestTimeout = 15 * time.Second

defaultListenAddress = "0.0.0.0:8083"

Expand All @@ -43,9 +44,8 @@ const (
cmdHelp = "help"
cmdVersion = "version"
cmdConfig = "config"
)

const (
cfgBearerCookieName = "bearer_cookie_name"
cfgOauth = "oauth"
cfgOauthIDFmt = "oauth.%s.id"
cfgOauthSecretFmt = "oauth.%s.secret"
Expand Down
2 changes: 2 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ listen_address: 0.0.0.0:8083
logger:
level: debug

bearer_cookie_name: "Bearer"

connect_timeout: 30s
request_timeout: 15s
rebalance_timer: 15s