Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 48fdc63

Browse files
author
Chris Warwick
authored
Update Access token defaults (#60190)
1 parent 9aaf435 commit 48fdc63

File tree

7 files changed

+33
-12
lines changed

7 files changed

+33
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ All notable changes to Sourcegraph are documented in this file.
2222
- Supports custom ChatCompletion models in Cody clients for dotcom users. [#58158](https://github.com/sourcegraph/sourcegraph/pull/58158)
2323
- Topics synced from GitHub and GitLab are now displayed for repository matches in the search results and on the repository tree page. [#58927](https://github.com/sourcegraph/sourcegraph/pull/58927)
2424
- Added a new column "Repository metadata JSON" to the CSV export of repository search results, which includes the JSON encoded object of metadata key-value pairs. [#59334](https://github.com/sourcegraph/sourcegraph/pull/59334)
25-
- Expiry to access tokens. Users can now select a maximum timespan for which a token is valid. Tokens will automatically lose access after this period. Default timeframes and an override to allow access tokens without expiration can be configured in the `auth.accessTokens` section of the site configuration. [#59565](https://github.com/sourcegraph/sourcegraph/pull/59565)
25+
- Expiry to access tokens. Users can now select a maximum timespan for which a token is valid. Tokens will automatically lose access after this period. Default timeframes and an override to disable access tokens without expiration can be configured in the `auth.accessTokens` section of the site configuration. [#59565](https://github.com/sourcegraph/sourcegraph/pull/59565)
2626
- Gerrit code host connections now support an 'exclude' field that prevents repos in this list from being synced. [#59739](https://github.com/sourcegraph/sourcegraph/pull/59739)
2727
- Limit the number of active access tokens for a user. By default users are able to have 25 active access tokens. This limit can be configured using the `maxTokensPerUser` setting in the `auth.accessTokens` section of the site configuration. [#59731](https://github.com/sourcegraph/sourcegraph/pull/59731)
2828
- Add experimental support for .cody/ignore when retrieving remote context. To enable it, set `experimentalFeatures.codyContextIgnore: true` in the site configuration. [#59836](https://github.com/sourcegraph/sourcegraph/pull/59836), [#59907](https://github.com/sourcegraph/sourcegraph/pull/59907)

cmd/frontend/graphqlbackend/access_tokens_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ func TestMutation_CreateAccessToken(t *testing.T) {
101101
t.Run("authenticated as user, expiration required not sent", func(t *testing.T) {
102102
ctx := actor.WithActor(context.Background(), &actor.Actor{UID: 1})
103103
db := dbmocks.NewMockDB()
104+
conf.Mock(&conf.Unified{
105+
SiteConfiguration: schema.SiteConfiguration{
106+
AuthAccessTokens: &schema.AuthAccessTokens{
107+
AllowNoExpiration: pointers.Ptr(false),
108+
},
109+
},
110+
})
111+
defer conf.Mock(nil)
104112
result, err := newSchemaResolver(db, gitserver.NewTestClient(t)).CreateAccessToken(ctx, &createAccessTokenInput{User: uid1GQLID, Scopes: []string{"user:all"}, Note: "n"})
105113
if err == nil {
106114
t.Error("err == nil")
@@ -132,7 +140,7 @@ func TestMutation_CreateAccessToken(t *testing.T) {
132140
db := dbmocks.NewMockDB()
133141
db.AccessTokensFunc.SetDefaultReturn(accessTokens)
134142
db.UsersFunc.SetDefaultReturn(users)
135-
conf.Get().AuthAccessTokens = &schema.AuthAccessTokens{Allow: string(conf.AccessTokensAll), AllowNoExpiration: true}
143+
conf.Get().AuthAccessTokens = &schema.AuthAccessTokens{Allow: string(conf.AccessTokensAll), AllowNoExpiration: pointers.Ptr(true)}
136144
defer func() { conf.Get().AuthAccessTokens = nil }()
137145
result, err := newSchemaResolver(db, gitserver.NewTestClient(t)).CreateAccessToken(ctx, &createAccessTokenInput{User: uid1GQLID, Scopes: []string{"user:all"}, Note: "n"})
138146
if err != nil {
@@ -150,7 +158,7 @@ func TestMutation_CreateAccessToken(t *testing.T) {
150158
conf.Mock(&conf.Unified{
151159
SiteConfiguration: schema.SiteConfiguration{
152160
AuthAccessTokens: &schema.AuthAccessTokens{
153-
AllowNoExpiration: false,
161+
AllowNoExpiration: pointers.Ptr(false),
154162
DefaultExpirationDays: pointers.Ptr(2),
155163
ExpirationOptionDays: []int{1, 2, 3},
156164
},

internal/conf/computed.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ func AccessTokensMaxPerUser() int {
8484
// AccessTokensAllowNoExpiration returns whether access tokens can be created without expiration.
8585
func AccessTokensAllowNoExpiration() bool {
8686
cfg := Get().AuthAccessTokens
87-
if cfg == nil {
88-
return false
87+
if cfg == nil || cfg.AllowNoExpiration == nil {
88+
return true
8989
}
90-
return cfg.AllowNoExpiration
90+
return *cfg.AllowNoExpiration
9191
}
9292

9393
// AccessTokensExpirationOptions returns the default access token expiration days

internal/conf/computed_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ func TestAccessTokenAllowNoExpiration(t *testing.T) {
12011201
{
12021202
name: "no accesstoken config set",
12031203
siteConfig: schema.SiteConfiguration{},
1204-
want: false,
1204+
want: true,
12051205
},
12061206
{
12071207
name: "default value",
@@ -1210,18 +1210,28 @@ func TestAccessTokenAllowNoExpiration(t *testing.T) {
12101210
Allow: string(AccessTokensAll),
12111211
},
12121212
},
1213-
want: false,
1213+
want: true,
12141214
},
12151215
{
12161216
name: "allow no expiration",
12171217
siteConfig: schema.SiteConfiguration{
12181218
AuthAccessTokens: &schema.AuthAccessTokens{
12191219
Allow: string(AccessTokensAll),
1220-
AllowNoExpiration: true,
1220+
AllowNoExpiration: pointers.Ptr(true),
12211221
},
12221222
},
12231223
want: true,
12241224
},
1225+
{
1226+
name: "do not allow no expiration",
1227+
siteConfig: schema.SiteConfiguration{
1228+
AuthAccessTokens: &schema.AuthAccessTokens{
1229+
Allow: string(AccessTokensAll),
1230+
AllowNoExpiration: pointers.Ptr(false),
1231+
},
1232+
},
1233+
want: false,
1234+
},
12251235
}
12261236

12271237
for _, tc := range testCases {

internal/database/access_tokens_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ func TestAccessTokens_Limits(t *testing.T) {
641641
SiteConfiguration: schema.SiteConfiguration{
642642
AuthAccessTokens: &schema.AuthAccessTokens{
643643
MaxTokensPerUser: pointers.Ptr(2),
644-
AllowNoExpiration: true,
644+
AllowNoExpiration: pointers.Ptr(true),
645645
},
646646
Log: &schema.Log{
647647
SecurityEventLog: &schema.SecurityEventLog{Location: "database"},

schema/schema.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/site.schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,10 @@
11641164
"allowNoExpiration": {
11651165
"description": "Allows new tokens to be created without specifying an expiration.",
11661166
"type": "boolean",
1167-
"default": "false"
1167+
"!go": {
1168+
"pointer": true
1169+
},
1170+
"default": "true"
11681171
},
11691172
"expirationOptionDays": {
11701173
"description": "Options users will see for the number of days until token expiration. The defaultExpirationDays will be added to the list if not already present.",

0 commit comments

Comments
 (0)