Skip to content

Commit e20deaa

Browse files
stgarfwlynch
andauthored
Add config options for Autoclose and AutocloseTimeout (#466)
* Add autoclose after auth feature Add the ability to have the window `autoclose` after the specified `autocloseTimeout`. If the go template cannot be rendered the page will fallback to the original static html page. Signed-off-by: Steve Garf <garf@chainguard.dev> * Update README and default values Signed-off-by: Steve Garf <garf@chainguard.dev> * Update README.md Co-authored-by: Billy Lynch <1844673+wlynch@users.noreply.github.com> Signed-off-by: stgarf <stgarf@users.noreply.github.com> --------- Signed-off-by: Steve Garf <garf@chainguard.dev> Signed-off-by: stgarf <stgarf@users.noreply.github.com> Co-authored-by: Billy Lynch <1844673+wlynch@users.noreply.github.com>
1 parent 3f2e97e commit e20deaa

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ The following config options are supported:
7575
| tokenProvider | | Optional OIDC token provider to use to fetch tokens. If not set, any available providers are used. valid values are:<br>- `interactive`<br>- `spiffe`<br>- `google-workload-identity`<br>- `google-impersonation`<br>- `github-actions`<br>- `filesystem`<br>- `buildkite-agent` |
7676
| timestampServerURL | | Address of timestamping authority. If set, a trusted timestamp will be included in the signature. |
7777
| timestampCertChain | | Path to PEM encoded certificate chain for RFC3161 Timestamp Authority verification. |
78+
| autoclose | true | If true, autoclose the browser window after `autocloseTimeout`. In order for autoclose to work you must also set `connectorID`. |
79+
| autocloseTimeout | 6 | If `autoclose` is true, this is how long to wait until the window is closed. |
7880

7981
### Environment Variables
8082

@@ -93,6 +95,8 @@ The following config options are supported:
9395
| GITSIGN_TIMESTAMP_CERT_CHAIN || | Path to PEM encoded certificate chain for RFC3161 Timestamp Authority verification. |
9496
| GITSIGN_FULCIO_ROOT || | Path to PEM encoded certificate for Fulcio CA (additional alias: SIGSTORE_ROOT_FILE) |
9597
| GITSIGN_REKOR_MODE || online | Rekor storage mode to operate in. One of [online, offline] (default: online)<br>online - Commit SHAs are stored in Rekor, requiring online verification for all commit objects.<br>offline - Hashed commit content is stored in Rekor, with Rekor attributes necessary for offline verification being stored in the commit itself.<br>Note: online verification will be deprecated in favor of offline in the future. |
98+
| GITSIGN_AUTOCLOSE || true | If true, autoclose the browser window after `GITSIGN_AUTOCLOSE_TIME`. |
99+
| GITSIGN_AUTOCLOSE_TIMEOUT || 6 | If `GITSIGN_AUTOCLOSE` is true, this is how long to wait until the window is closed. |
96100

97101
For environment variables that support `Sigstore Prefix`, the values may be
98102
provided with either a `GITSIGN_` or `SIGSTORE_` prefix - e.g.

internal/config/config.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import (
1919
"bytes"
2020
"fmt"
2121
"io"
22+
"log"
2223
"os"
2324
"os/exec"
25+
"strconv"
2426
"strings"
2527
)
2628

@@ -80,6 +82,11 @@ type Config struct {
8082
CommitterName string
8183
CommitterEmail string
8284
MatchCommitter bool
85+
86+
// Autoclose specifies whether to close window after successful authentication
87+
Autoclose bool
88+
// AutocloseTimeout specifies the time to wait before closing the window
89+
AutocloseTimeout int
8390
}
8491

8592
// Get fetches the gitsign config options for the repo in the current working
@@ -98,7 +105,9 @@ func Get() (*Config, error) {
98105
ClientID: "sigstore",
99106
Issuer: "https://oauth2.sigstore.dev/auth",
100107
// TODO: default to offline
101-
RekorMode: "online",
108+
RekorMode: "online",
109+
Autoclose: true,
110+
AutocloseTimeout: 6,
102111
}
103112

104113
// Get values from config file.
@@ -124,6 +133,8 @@ func Get() (*Config, error) {
124133
out.TokenProvider = envOrValue(fmt.Sprintf("%s_TOKEN_PROVIDER", prefix), out.TokenProvider)
125134
out.TimestampURL = envOrValue(fmt.Sprintf("%s_TIMESTAMP_SERVER_URL", prefix), out.TimestampURL)
126135
out.TimestampCert = envOrValue(fmt.Sprintf("%s_TIMESTAMP_CERT_CHAIN", prefix), out.TimestampCert)
136+
out.Autoclose = envOrValue(fmt.Sprintf("%s_AUTOCLOSE", prefix), fmt.Sprintf("%t", out.Autoclose)) == "true"
137+
out.AutocloseTimeout, _ = strconv.Atoi(envOrValue(fmt.Sprintf("%s_AUTOCLOSE_TIMEOUT", prefix), fmt.Sprintf("%d", out.AutocloseTimeout)))
127138
}
128139

129140
out.LogPath = envOrValue("GITSIGN_LOG", out.LogPath)
@@ -203,6 +214,15 @@ func applyGitOptions(out *Config, cfg map[string]string) {
203214
out.TimestampCert = v
204215
case strings.EqualFold(k, "gitsign.matchCommitter"):
205216
out.MatchCommitter = strings.EqualFold(v, "true")
217+
case strings.EqualFold(k, "gitsign.autoclose"):
218+
out.Autoclose = strings.EqualFold(v, "true")
219+
case strings.EqualFold(k, "gitsign.autocloseTimeout"):
220+
if i, err := strconv.Atoi(v); err == nil && i > 0 {
221+
out.AutocloseTimeout = i
222+
} else {
223+
log.Printf("invalid gitsign.autocloseTimeout value %q, defaulting to 6", v)
224+
out.AutocloseTimeout = 6
225+
}
206226
}
207227
}
208228
}

internal/config/config_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ func TestGet(t *testing.T) {
8282
// Default value
8383
ClientID: "sigstore",
8484
// Overridden by env var
85-
Issuer: "tacocat",
86-
RedirectURL: "example.com",
87-
ConnectorID: "bar",
88-
RekorMode: "online",
85+
Issuer: "tacocat",
86+
RedirectURL: "example.com",
87+
ConnectorID: "bar",
88+
RekorMode: "online",
89+
Autoclose: true,
90+
AutocloseTimeout: 6,
8991
}
9092

9193
execFn = func() (io.Reader, error) {

internal/fulcio/identity.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ func (f *IdentityFactory) NewIdentity(ctx context.Context, cfg *config.Config) (
197197

198198
// Autoclose only works if we don't go through the identity selection page
199199
// (otherwise it'll show a countdown timer that doesn't work)
200-
autoclose := false
201-
if cfg.ConnectorID != "" {
202-
autoclose = true
200+
if cfg.ConnectorID == "" {
201+
cfg.Autoclose = false
203202
}
204-
html, err := oauth.GetInteractiveSuccessHTML(autoclose, 6)
203+
html, err := oauth.GetInteractiveSuccessHTML(cfg.Autoclose, cfg.AutocloseTimeout)
205204
if err != nil {
206-
return nil, fmt.Errorf("error generating interactive HTML: %w", err)
205+
fmt.Println("error getting interactive success html, using static default", err)
206+
html = oauth.InteractiveSuccessHTML
207207
}
208208
defaultFlow := &oauthflow.InteractiveIDTokenGetter{
209209
HTMLPage: html,

0 commit comments

Comments
 (0)