Skip to content

Commit 69aa630

Browse files
authored
Fix references to level_token_db.path and http_timeout example (#383)
1 parent aab2ae0 commit 69aa630

File tree

6 files changed

+42
-47
lines changed

6 files changed

+42
-47
lines changed

auth_server/authn/github_auth.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"errors"
2323
"fmt"
2424
"html/template"
25-
"io/ioutil"
25+
"io"
2626
"net/http"
2727
"net/url"
2828
"strings"
@@ -117,7 +117,6 @@ func execGHExperimentalApiRequest(url string, token string) (*http.Response, err
117117
}
118118

119119
// removeSubstringsFromString removes all occurences of stringsToStrip from sourceStr
120-
//
121120
func removeSubstringsFromString(sourceStr string, stringsToStrip []string) string {
122121
theNewString := sourceStr
123122
for _, i := range stringsToStrip {
@@ -129,7 +128,6 @@ func removeSubstringsFromString(sourceStr string, stringsToStrip []string) strin
129128
// parseLinkHeader parses the HTTP headers from the Github API response
130129
//
131130
// https://developer.github.com/v3/guides/traversing-with-pagination/
132-
//
133131
func parseLinkHeader(linkLines []string) (linkHeader, error) {
134132
var lH linkHeader
135133
// URL in link is enclosed in < >
@@ -255,7 +253,7 @@ func (gha *GitHubAuth) doGitHubAuthCreateToken(rw http.ResponseWriter, code stri
255253
http.Error(rw, fmt.Sprintf("Error talking to GitHub auth backend: %s", err), http.StatusServiceUnavailable)
256254
return
257255
}
258-
codeResp, _ := ioutil.ReadAll(resp.Body)
256+
codeResp, _ := io.ReadAll(resp.Body)
259257
resp.Body.Close()
260258
glog.V(2).Infof("Code to token resp: %s", strings.Replace(string(codeResp), "\n", " ", -1))
261259

@@ -317,7 +315,7 @@ func (gha *GitHubAuth) validateAccessToken(token string) (user string, err error
317315
err = fmt.Errorf("could not verify token %s: %s", token, err)
318316
return
319317
}
320-
body, _ := ioutil.ReadAll(resp.Body)
318+
body, _ := io.ReadAll(resp.Body)
321319
resp.Body.Close()
322320

323321
var ti GitHubTokenUser
@@ -386,7 +384,7 @@ func (gha *GitHubAuth) fetchTeams(token string) ([]string, error) {
386384
}
387385

388386
respHeaders := resp.Header
389-
body, _ := ioutil.ReadAll(resp.Body)
387+
body, _ := io.ReadAll(resp.Body)
390388
resp.Body.Close()
391389

392390
err = json.Unmarshal(body, &pagedTeams)

auth_server/authn/gitlab_auth.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"errors"
2323
"fmt"
2424
"html/template"
25-
"io/ioutil"
25+
"io"
2626
"net/http"
2727
"net/url"
2828
"strings"
@@ -103,7 +103,6 @@ type GitlabAuth struct {
103103
tmplResult *template.Template
104104
}
105105

106-
107106
func NewGitlabAuth(c *GitlabAuthConfig) (*GitlabAuth, error) {
108107
var db TokenDB
109108
var err error
@@ -205,7 +204,7 @@ func (glab *GitlabAuth) doGitlabAuthCreateToken(rw http.ResponseWriter, code str
205204
http.Error(rw, fmt.Sprintf("Error talking to GitLab auth backend: %s", err), http.StatusServiceUnavailable)
206205
return
207206
}
208-
codeResp, _ := ioutil.ReadAll(resp.Body)
207+
codeResp, _ := io.ReadAll(resp.Body)
209208
resp.Body.Close()
210209
glog.V(2).Infof("Code to token resp: %s", strings.Replace(string(codeResp), "\n", " ", -1))
211210

@@ -230,7 +229,6 @@ func (glab *GitlabAuth) doGitlabAuthCreateToken(rw http.ResponseWriter, code str
230229

231230
glog.Infof("New GitLab auth token for %s", user)
232231

233-
234232
v := &TokenDBValue{
235233
TokenType: c2t.TokenType,
236234
AccessToken: c2t.AccessToken,
@@ -247,7 +245,7 @@ func (glab *GitlabAuth) doGitlabAuthCreateToken(rw http.ResponseWriter, code str
247245

248246
func (glab *GitlabAuth) validateGitlabAccessToken(token string) (user string, err error) {
249247
glog.Infof("Gitlab API: Fetching user info")
250-
req, err := http.NewRequest("GET", fmt.Sprintf("%s/user", glab.getGitlabApiUri()),nil)
248+
req, err := http.NewRequest("GET", fmt.Sprintf("%s/user", glab.getGitlabApiUri()), nil)
251249

252250
if err != nil {
253251
err = fmt.Errorf("could not create request to get information for token %s: %s", token, err)
@@ -261,7 +259,7 @@ func (glab *GitlabAuth) validateGitlabAccessToken(token string) (user string, er
261259
err = fmt.Errorf("could not verify token %s: %s", token, err)
262260
return
263261
}
264-
body, _ := ioutil.ReadAll(resp.Body)
262+
body, _ := io.ReadAll(resp.Body)
265263
resp.Body.Close()
266264
var ti GitlabTokenUser
267265
err = json.Unmarshal(body, &ti)
@@ -302,7 +300,6 @@ func (glab *GitlabAuth) checkGitlabOrganization(token, user string) (err error)
302300
return fmt.Errorf("Unknown status for membership of organization %s: %s", glab.config.Organization, resp.Status)
303301
}
304302

305-
306303
func (glab *GitlabAuth) validateGitlabServerToken(user string) (*TokenDBValue, error) {
307304
v, err := glab.db.GetValue(user)
308305
if err != nil || v == nil {

auth_server/authn/google_auth.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"html/template"
24-
"io/ioutil"
24+
"io"
2525
"net/http"
2626
"net/url"
2727
"strings"
@@ -162,7 +162,7 @@ func (ga *GoogleAuth) DoGoogleAuth(rw http.ResponseWriter, req *http.Request) {
162162
ga.doGoogleAuthPage(rw, req)
163163
return
164164
}
165-
gauthRequest, _ := ioutil.ReadAll(req.Body)
165+
gauthRequest, _ := io.ReadAll(req.Body)
166166
glog.V(2).Infof("gauth request: %s", string(gauthRequest))
167167
var gar GoogleAuthRequest
168168
err := json.Unmarshal(gauthRequest, &gar)
@@ -203,7 +203,7 @@ func (ga *GoogleAuth) doGoogleAuthCreateToken(rw http.ResponseWriter, code strin
203203
http.Error(rw, fmt.Sprintf("Error talking to Google auth backend: %s", err), http.StatusServiceUnavailable)
204204
return
205205
}
206-
codeResp, _ := ioutil.ReadAll(resp.Body)
206+
codeResp, _ := io.ReadAll(resp.Body)
207207
resp.Body.Close()
208208
glog.V(2).Infof("Code to token resp: %s", strings.Replace(string(codeResp), "\n", " ", -1))
209209

@@ -262,7 +262,7 @@ func (ga *GoogleAuth) getIDTokenInfo(token string) (*GoogleTokenInfo, error) {
262262
if err != nil {
263263
return nil, fmt.Errorf("could not verify token %s: %s", token, err)
264264
}
265-
body, _ := ioutil.ReadAll(resp.Body)
265+
body, _ := io.ReadAll(resp.Body)
266266
resp.Body.Close()
267267

268268
var ti GoogleTokenInfo
@@ -317,7 +317,7 @@ func (ga *GoogleAuth) refreshAccessToken(refreshToken string) (rtr RefreshTokenR
317317
err = fmt.Errorf("Error talking to Google auth backend: %s", err)
318318
return
319319
}
320-
respStr, _ := ioutil.ReadAll(resp.Body)
320+
respStr, _ := io.ReadAll(resp.Body)
321321
glog.V(2).Infof("Refresh token resp: %s", strings.Replace(string(respStr), "\n", " ", -1))
322322

323323
err = json.Unmarshal(respStr, &rtr)
@@ -334,7 +334,7 @@ func (ga *GoogleAuth) validateAccessToken(toktype, token string) (user string, e
334334
if err != nil {
335335
return
336336
}
337-
respStr, _ := ioutil.ReadAll(resp.Body)
337+
respStr, _ := io.ReadAll(resp.Body)
338338
glog.V(2).Infof("Access token validation rrsponse: %s", strings.Replace(string(respStr), "\n", " ", -1))
339339
var pr ProfileResponse
340340
err = json.Unmarshal(respStr, &pr)

auth_server/authn/oidc_auth.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"errors"
2323
"fmt"
2424
"html/template"
25-
"io/ioutil"
25+
"io"
2626
"net/http"
2727
"strings"
2828
"time"
@@ -40,29 +40,29 @@ import (
4040
type OIDCAuthConfig struct {
4141
// --- necessary ---
4242
// URL of the authentication provider. Must be able to serve the /.well-known/openid-configuration
43-
Issuer string `yaml:"issuer,omitempty"`
43+
Issuer string `yaml:"issuer,omitempty"`
4444
// URL of the auth server. Has to end with /oidc_auth
45-
RedirectURL string `yaml:"redirect_url,omitempty"`
45+
RedirectURL string `yaml:"redirect_url,omitempty"`
4646
// ID and secret, priovided by the OIDC provider after registration of the auth server
47-
ClientId string `yaml:"client_id,omitempty"`
48-
ClientSecret string `yaml:"client_secret,omitempty"`
49-
ClientSecretFile string `yaml:"client_secret_file,omitempty"`
47+
ClientId string `yaml:"client_id,omitempty"`
48+
ClientSecret string `yaml:"client_secret,omitempty"`
49+
ClientSecretFile string `yaml:"client_secret_file,omitempty"`
5050
// path where the tokendb should be stored within the container
51-
LevelTokenDB *LevelDBStoreConfig `yaml:"level_token_db,omitempty"`
52-
GCSTokenDB *GCSStoreConfig `yaml:"gcs_token_db,omitempty"`
53-
RedisTokenDB *RedisStoreConfig `yaml:"redis_token_db,omitempty"`
51+
LevelTokenDB *LevelDBStoreConfig `yaml:"level_token_db,omitempty"`
52+
GCSTokenDB *GCSStoreConfig `yaml:"gcs_token_db,omitempty"`
53+
RedisTokenDB *RedisStoreConfig `yaml:"redis_token_db,omitempty"`
5454
// --- optional ---
55-
HTTPTimeout time.Duration `yaml:"http_timeout,omitempty"`
55+
HTTPTimeout time.Duration `yaml:"http_timeout,omitempty"`
5656
// the URL of the docker registry. Used to generate a full docker login command after authentication
57-
RegistryURL string `yaml:"registry_url,omitempty"`
57+
RegistryURL string `yaml:"registry_url,omitempty"`
5858
// --- optional ---
5959
// String claim to use for the username
60-
UserClaim string `yaml:"user_claim,omitempty"`
60+
UserClaim string `yaml:"user_claim,omitempty"`
6161
// --- optional ---
6262
// []string to add as labels.
63-
LabelsClaims []string `yaml:"labels_claims,omitempty"`
63+
LabelsClaims []string `yaml:"labels_claims,omitempty"`
6464
// --- optional ---
65-
Scopes []string `yaml:"scopes,omitempty"`
65+
Scopes []string `yaml:"scopes,omitempty"`
6666
}
6767

6868
// OIDCRefreshTokenResponse is sent by OIDC provider in response to the grant_type=refresh_token request.
@@ -274,7 +274,7 @@ func (ga *OIDCAuth) refreshAccessToken(refreshToken string) (rtr OIDCRefreshToke
274274
err = fmt.Errorf("error talking to OIDC auth backend: %s", err)
275275
return
276276
}
277-
respStr, _ := ioutil.ReadAll(resp.Body)
277+
respStr, _ := io.ReadAll(resp.Body)
278278
glog.V(2).Infof("Refresh token resp: %s", strings.Replace(string(respStr), "\n", " ", -1))
279279

280280
err = json.Unmarshal(respStr, &rtr)

auth_server/server/config.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ func validate(c *Config) error {
193193
}
194194
gac.ClientSecret = strings.TrimSpace(string(contents))
195195
}
196-
if gac.ClientId == "" || gac.ClientSecret == "" || (gac.LevelTokenDB == nil && (gac.GCSTokenDB == nil && gac.RedisTokenDB == nil)) {
197-
return errors.New("google_auth.{client_id,client_secret,token_db} are required")
196+
if gac.ClientId == "" || gac.ClientSecret == "" || (gac.LevelTokenDB != nil && gac.LevelTokenDB.Path == "") {
197+
return errors.New("google_auth.{client_id,client_secret,level_token_db.path} are required")
198198
}
199199

200200
if gac.ClientId == "" || gac.ClientSecret == "" || (gac.GCSTokenDB != nil && (gac.GCSTokenDB.Bucket == "" || gac.GCSTokenDB.ClientSecretFile == "")) {
@@ -217,8 +217,8 @@ func validate(c *Config) error {
217217
}
218218
ghac.ClientSecret = strings.TrimSpace(string(contents))
219219
}
220-
if ghac.ClientId == "" || ghac.ClientSecret == "" || (ghac.LevelTokenDB == nil && (ghac.GCSTokenDB == nil && ghac.RedisTokenDB == nil)) {
221-
return errors.New("github_auth.{client_id,client_secret,token_db} are required")
220+
if ghac.ClientId == "" || ghac.ClientSecret == "" || (ghac.LevelTokenDB != nil && ghac.LevelTokenDB.Path == "") {
221+
return errors.New("github_auth.{client_id,client_secret,level_token_db.path} are required")
222222
}
223223

224224
if ghac.ClientId == "" || ghac.ClientSecret == "" || (ghac.GCSTokenDB != nil && (ghac.GCSTokenDB.Bucket == "" || ghac.GCSTokenDB.ClientSecretFile == "")) {
@@ -245,8 +245,8 @@ func validate(c *Config) error {
245245
}
246246
oidc.ClientSecret = strings.TrimSpace(string(contents))
247247
}
248-
if oidc.ClientId == "" || oidc.ClientSecret == "" || oidc.Issuer == "" || oidc.RedirectURL == "" || (oidc.LevelTokenDB == nil && (oidc.GCSTokenDB == nil && oidc.RedisTokenDB == nil)) {
249-
return errors.New("oidc_auth.{issuer,redirect_url,client_id,client_secret,token_db} are required")
248+
if oidc.ClientId == "" || oidc.ClientSecret == "" || oidc.Issuer == "" || oidc.RedirectURL == "" || (oidc.LevelTokenDB != nil && oidc.LevelTokenDB.Path == "") {
249+
return errors.New("oidc_auth.{issuer,redirect_url,client_id,client_secret,level_token_db.path} are required")
250250
}
251251

252252
if oidc.ClientId == "" || oidc.ClientSecret == "" || (oidc.GCSTokenDB != nil && (oidc.GCSTokenDB.Bucket == "" || oidc.GCSTokenDB.ClientSecretFile == "")) {
@@ -275,8 +275,8 @@ func validate(c *Config) error {
275275
}
276276
glab.ClientSecret = strings.TrimSpace(string(contents))
277277
}
278-
if glab.ClientId == "" || glab.ClientSecret == "" || (glab.LevelTokenDB == nil && (glab.GCSTokenDB == nil && glab.RedisTokenDB == nil)) {
279-
return errors.New("gitlab_auth.{client_id,client_secret,token_db} are required")
278+
if glab.ClientId == "" || glab.ClientSecret == "" || (glab.LevelTokenDB != nil && glab.LevelTokenDB.Path == "") {
279+
return errors.New("gitlab_auth.{client_id,client_secret,level_token_db.path} are required")
280280
}
281281

282282
if glab.ClientId == "" || glab.ClientSecret == "" || (glab.GCSTokenDB != nil && (glab.GCSTokenDB.Bucket == "" || glab.GCSTokenDB.ClientSecretFile == "")) {

examples/reference.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ google_auth:
120120
# Optional token hash cost for bcrypt hashing
121121
# token_hash_cost: 5
122122
# How long to wait when talking to Google servers. Optional.
123-
http_timeout: 10
123+
http_timeout: "10s"
124124

125125
# GitHub authentication.
126126
# ==! NB: DO NOT ENTER YOUR GITHUB PASSWORD AT "docker login". IT WILL NOT WORK.
@@ -139,7 +139,7 @@ github_auth:
139139
# client_secret: "verysecret"
140140
client_secret_file: "/path/to/client_secret.txt"
141141
# Either level_token_db file for storing of server tokens.
142-
level_token_db:
142+
level_token_db:
143143
path: "/somewhere/to/put/github_tokens.ldb"
144144
# Optional token hash cost for bcrypt hashing
145145
# token_hash_cost: 5
@@ -187,13 +187,13 @@ oidc_auth:
187187
# client_secret_file: "/path/to/client_secret.txt"
188188
#
189189
# a file in which the tokens should be stored. Does not have to exist, it will be generated in this case
190-
level_token_db:
190+
level_token_db:
191191
path: "/path/to/tokens.ldb"
192192
# Optional token hash cost for bcrypt hashing
193193
# token_hash_cost: 5
194194
# --- optional ---
195195
# How long to wait when talking to the OIDC provider.
196-
http_timeout: 10
196+
http_timeout: "10s"
197197
# the url of the registry where you want to login. Is used to present the full docker login command.
198198
registry_url: "url_of_my_beautiful_docker_registry"
199199
# The claim to use for the username.
@@ -220,7 +220,7 @@ gitlab_auth:
220220
# client_secret: "verysecret"
221221
client_secret_file: "/path/to/client_secret.txt"
222222
# Either level_token_db file for storing of server tokens.
223-
level_token_db:
223+
level_token_db:
224224
path: "/somewhere/to/put/gitlab_tokens.ldb"
225225
# Optional token hash cost for bcrypt hashing
226226
# token_hash_cost: 5

0 commit comments

Comments
 (0)