Skip to content
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
4 changes: 2 additions & 2 deletions convox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
# Pinned to an immutable release tag. scripts/bump-version.sh sets it to the new
# version (:vX.Y.Z); the release workflow publishes that tag when the v* git tag is pushed.
# :e327add is the v0.1.1 release (identical to :latest when this was pinned).
image: docker.io/docspringcom/rack-gateway:v0.1.32
image: docker.io/docspringcom/rack-gateway:v0.1.33
command: ./scripts/start-gateway.sh
environment:
- PORT=8080
Expand All @@ -54,7 +54,7 @@ services:

admin:
# Uses same image as gateway service (kept in sync by scripts/bump-version.sh)
image: docker.io/docspringcom/rack-gateway:v0.1.32
image: docker.io/docspringcom/rack-gateway:v0.1.33
command: echo "Use this service to run migrations, database admin tasks, etc."
environment:
- PORT=8080
Expand Down
5 changes: 3 additions & 2 deletions docs/src/content/docs/integrations/deploy-approvals/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ each listed rack. If any is missing, it approves nothing and exits non-zero, nam
so a retry approves them all together. Requests that are already approved or deployed count as done.

From a terminal it asks you to press Enter before approving. Scripts and AI agents (no terminal) skip that prompt.
Instead, the macOS PIN dialog lists every approval the command makes (app, rack, short commit and message) above
the command line, and each approval needs a key touch. The dialog masks `KEY=value` arguments and the values of
Instead, the macOS PIN dialog lists every approval the command makes above the command line, each starting with
its branch, then its app, rack, short commit and message. Each approval needs a key touch, and the touch prompt
and notification name the branch too. The dialog masks `KEY=value` arguments and the values of
flags that can carry secrets (tokens, passwords, keys, MFA codes); other flag values such as `--app`, `--rack` and
`--commit` are shown. Without a terminal the command line must also say exactly what is approved: an explicit
`--app` list and a full 40-character `--commit`, with no `--branch` or `--all-apps`.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/user-guide/cli/mfa-verification.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The CLI supports multiple MFA methods:

```
Multi-factor authentication required (WebAuthn).
Touch your security key to approve api on staging (2 of 4)... (press Ctrl+C to abort)
Touch your security key to approve feature/fix-login (api on staging, 2 of 4)... (press Ctrl+C to abort)
```

The CLI prompts you to touch your hardware security key, and says what the touch is for. User verification is
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/deploy_approvals_approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ nothing is approved and the command fails.

From a terminal it asks for Enter first. Without a terminal (scripts, AI agents) it doesn't, and it needs an
explicit --app list and a full 40-character --commit (no --branch or --all-apps). The macOS PIN dialog then lists
every approval the command makes (app, rack, commit and message) above the command line.
every approval the command makes (branch, app, rack, commit and message) above the command line.

Examples:
# Show a request and approve it
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/deploy_approvals_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestApproveByIDShowsTheRequestBeforeApproving(t *testing.T) {
require.Contains(t, shown, want, "the request is shown before it is approved")
}
require.NotContains(t, shown, "\x1b[2J", "CI-supplied text is shown safely")
require.Contains(t, gateway.output.String(), approveFlowRequestID+" (web, commit 36a302d01234) approved")
require.Contains(t, gateway.output.String(), approveFlowRequestID+" (web, commit 36a302d) approved")
}

func TestApproveByIDOnlyApprovesPendingRequests(t *testing.T) {
Expand Down Expand Up @@ -283,14 +283,14 @@ func TestApprovalSummaryDescribesEachApproval(t *testing.T) {

got := approvalSummary([]rackApproval{{rack: "staging", req: &web}, {rack: "us", req: &unnamed}})
require.Equal(t, []string{
`web on staging, commit 36a302d01234: "Deploy web?with a second line"`,
`request p-unnamed on us, commit 36a302d01234: "Deploy "`,
`main: web on staging, commit 36a302d, "Deploy web?with a second line"`,
`main: request p-unnamed on us, commit 36a302d, "Deploy "`,
}, got)
}

func TestShortCommit(t *testing.T) {
require.Equal(t, "36a302d01234", shortCommit(appsTestCommit))
require.Equal(t, "36a302d", shortCommit("36a302d"))
require.Equal(t, "36a302d", shortCommit(appsTestCommit))
require.Equal(t, "36a3", shortCommit("36a3"))
require.Equal(t, "(none)", shortCommit(""))
require.Equal(t, "?[2J", shortCommit("\x1b[2J"))
}
2 changes: 1 addition & 1 deletion internal/cli/deploy_approvals_show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ func TestApprovalTouchAndSummaryNeutralizeTheRequestID(t *testing.T) {
req := &deployApprovalRequest{PublicID: "req-1\x1b[2J", GitCommitHash: appsTestCommit, Message: "Deploy"}

require.Equal(t, "approve request req-1?[2J on us", approvalTouch("us", req, 0, 0))
require.Equal(t, `request req-1?[2J on us, commit 36a302d01234: "Deploy"`, approvalSummaryLine("us", req))
require.Equal(t, `request req-1?[2J on us, commit 36a302d, "Deploy"`, approvalSummaryLine("us", req))
}
64 changes: 48 additions & 16 deletions internal/cli/deploy_approvals_summary.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package cli

import "fmt"
import (
"fmt"
"strings"

// shortCommitLength is how much of a commit SHA one-line summaries show.
const shortCommitLength = 12
"github.com/DocSpring/rack-gateway/internal/cli/pinentry"
)

const (
// shortCommitLength is how much of a commit SHA one-line summaries show.
shortCommitLength = 7
// maxBranchRunes keeps a long branch name from pushing the app and rack out of a PIN dialog line, which the
// dialog cuts at 160 characters.
maxBranchRunes = 80
)

// shortCommit abbreviates a commit SHA for one-line summaries.
func shortCommit(hash string) string {
Expand All @@ -17,6 +27,19 @@ func shortCommit(hash string) string {
return string(runes)
}

// approvalBranch is the request's branch for one-line summaries, cut to maxBranchRunes, or "" when it has none.
func approvalBranch(req *deployApprovalRequest) string {
return pinentry.SingleLine(displayText(strings.TrimSpace(req.GitBranch)), maxBranchRunes)
}

// approvalApp names the request's app, or the request itself when it has none.
func approvalApp(req *deployApprovalRequest) string {
if app := displayText(req.App); app != "" {
return app
}
return "request " + displayText(req.PublicID)
}

// approvalTarget names what a request deploys: its app and short commit.
func approvalTarget(req *deployApprovalRequest) string {
commit := "commit " + shortCommit(req.GitCommitHash)
Expand All @@ -26,29 +49,38 @@ func approvalTarget(req *deployApprovalRequest) string {
return displayText(req.App) + ", " + commit
}

// approvalTouch says what the security key touch for an approval is for, e.g. "approve api on staging (2 of 4)".
// approvalTouch says what the security key touch for an approval is for. The branch comes first, since it's what
// the person approving recognizes: "approve feature/fix-login (api on staging, 2 of 4)", or "approve api on staging
// (2 of 4)" for a request without one. Later touches of a run come without a PIN dialog, so this is all they show.
// total is how many approvals the command makes, when it knows (0 otherwise).
func approvalTouch(rack string, req *deployApprovalRequest, current, total int) string {
app := displayText(req.App)
if app == "" {
app = "request " + displayText(req.PublicID)
subject := approvalApp(req) + " on " + displayText(rack)
var details []string
if branch := approvalBranch(req); branch != "" {
details = append(details, subject)
subject = branch
}
touch := fmt.Sprintf("approve %s on %s", app, displayText(rack))
if total > 1 {
touch += fmt.Sprintf(" (%d of %d)", current, total)
details = append(details, fmt.Sprintf("%d of %d", current, total))
}
touch := "approve " + subject
if len(details) > 0 {
touch += " (" + strings.Join(details, ", ") + ")"
}
return touch
}

// approvalSummaryLine describes one approval for the PIN dialog: the app, the rack, the commit and the message.
// approvalSummaryLine describes one approval for the PIN dialog: the branch first (see approvalTouch), then the app,
// the rack, the short commit and the message, e.g. `feature/fix-login: api on staging, commit 36a302d, "Fix login"`.
func approvalSummaryLine(rack string, req *deployApprovalRequest) string {
app := displayText(req.App)
if app == "" {
app = "request " + displayText(req.PublicID)
}
return fmt.Sprintf(
"%s on %s, commit %s: \"%s\"", app, displayText(rack), shortCommit(req.GitCommitHash), displayText(req.Message),
line := fmt.Sprintf(
"%s on %s, commit %s, \"%s\"",
approvalApp(req), displayText(rack), shortCommit(req.GitCommitHash), displayText(req.Message),
)
if branch := approvalBranch(req); branch != "" {
return branch + ": " + line
}
return line
}

// approvalSummary describes the approvals for the PIN dialog, one line per request.
Expand Down
37 changes: 37 additions & 0 deletions internal/cli/deploy_approvals_summary_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -18,3 +19,39 @@ func TestApprovalTouch(t *testing.T) {
req.App = "api\x1b[2J"
require.NotContains(t, approvalTouch("us", req, 0, 0), "\x1b", "control characters are removed")
}

// The branch is what the person approving recognizes, so it comes first. A run's later touches have no PIN dialog.
func TestApprovalTouchNamesTheBranchFirst(t *testing.T) {
req := &deployApprovalRequest{PublicID: "req-1", App: "api", GitBranch: "feature/fix-login"}
require.Equal(t, "approve feature/fix-login (api on staging, 2 of 4)", approvalTouch("staging", req, 2, 4))
require.Equal(t, "approve feature/fix-login (api on staging)", approvalTouch("staging", req, 0, 0))

req.GitBranch = " "
require.Equal(t, "approve api on staging", approvalTouch("staging", req, 0, 0), "a blank branch is left out")

req.GitBranch = "fix\x1b[2J"
require.Equal(t, "approve fix?[2J (api on staging)", approvalTouch("staging", req, 0, 0))
}

func TestApprovalSummaryLineNamesTheBranchFirst(t *testing.T) {
req := &deployApprovalRequest{
PublicID: "req-1", App: "api", GitBranch: "feature/fix-login", GitCommitHash: appsTestCommit,
Message: "Fix login",
}
require.Equal(t,
`feature/fix-login: api on staging, commit 36a302d, "Fix login"`, approvalSummaryLine("staging", req))

req.GitBranch = ""
require.Equal(t, `api on staging, commit 36a302d, "Fix login"`, approvalSummaryLine("staging", req))
}

// The PIN dialog cuts each line at 160 characters. A long branch is cut first, so the app and rack still show.
func TestApprovalSummaryLineCutsALongBranch(t *testing.T) {
branch := strings.Repeat("b", 300)
req := &deployApprovalRequest{App: "api", GitBranch: branch, GitCommitHash: appsTestCommit, Message: "Fix"}

line := approvalSummaryLine("staging", req)
require.True(t, strings.HasPrefix(line, strings.Repeat("b", maxBranchRunes)+"...: api on staging, commit 36a302d"))
require.Less(t, len([]rune(line)), 160)
require.Contains(t, approvalTouch("staging", req, 0, 0), "(api on staging)")
}
14 changes: 7 additions & 7 deletions internal/cli/deploy_approvals_wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestWaitShowsTheCommitOfEachRequest(t *testing.T) {
out := gateway.output.String()
require.Contains(t, out, "Deploy Approval Request Found")
require.Contains(t, out, appsTestCommit, "the pending request's details show its full commit")
require.Contains(t, out, "✓ Already approved on rack staging: a-worker (worker, commit 36a302d01234)")
require.Contains(t, out, "✓ Already approved on rack staging: a-worker (worker, commit 36a302d)")
require.Empty(t, gateway.seen(), "without --approve, wait only shows requests")
}

Expand All @@ -51,8 +51,8 @@ func TestWaitApproveShowsTheRequestAndSummarizesTheCommit(t *testing.T) {
}

require.NoError(t, waiter.printSummary())
require.Contains(t, gateway.output.String(), "p-web (web, commit 36a302d01234) approved")
require.Contains(t, gateway.output.String(), "staging web p-web commit 36a302d01234")
require.Contains(t, gateway.output.String(), "p-web (web, commit 36a302d) approved")
require.Contains(t, gateway.output.String(), "staging web p-web commit 36a302d")
}

// The newest request for a branch can be for any commit, so approving by branch alone needs a confirmation.
Expand Down Expand Up @@ -121,17 +121,17 @@ func TestWaitPINSummaryListsEveryApprovalTheRunCanMake(t *testing.T) {
waiter.markHandled("staging", web)
waiter.markHandled("us", shownRequest("a-worker", "worker", "approved"))
require.Equal(t, []string{
`web on staging, commit 36a302d01234: "Deploy web"`,
"worker on staging, commit 36a302d01234 (when its request appears)",
"web on us, commit 36a302d01234 (when its request appears)",
`main: web on staging, commit 36a302d, "Deploy web"`,
"worker on staging, commit 36a302d (when its request appears)",
"web on us, commit 36a302d (when its request appears)",
}, waiter.pinSummary("staging", web))

byBranch := newDeployApprovalWaiter(&cobra.Command{}, deployApprovalWaitConfig{
racks: []string{"staging"}, apps: apps, branch: "main", autoApprove: true,
})
byBranch.markHandled("staging", web)
require.Equal(t, []string{
`web on staging, commit 36a302d01234: "Deploy web"`,
`main: web on staging, commit 36a302d, "Deploy web"`,
"worker on staging, branch main (when its request appears)",
}, byBranch.pinSummary("staging", web))
}
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "0.1.32",
"version": "0.1.33",
"private": true,
"type": "module",
"scripts": {
Expand Down