Skip to content

Commit

Permalink
spiffe: correct trust domain checking
Browse files Browse the repository at this point in the history
Fixes an incorrect trust domain check to ensure that issuers are a
subdomain of the spiffe id trust domain.

Signed-off-by: Nathan Smith <nathan@chainguard.dev>
  • Loading branch information
Nathan Smith committed May 16, 2022
1 parent fdaedd6 commit bce3a8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/challenges/challenges.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func isSpiffeIDAllowed(host, spiffeID string) bool {
if u.Hostname() == host {
return true
}
return strings.Contains(u.Hostname(), "."+host)
return strings.HasSuffix(u.Hostname(), "."+host)
}

// isURISubjectAllowed compares the subject and issuer URIs,
Expand Down
16 changes: 16 additions & 0 deletions pkg/challenges/challenges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,23 @@ func Test_isSpiffeIDAllowed(t *testing.T) {
host: "foobar.com",
spiffeID: "spiffe://foofoobar.com/stuff",
want: false,
}, {
name: "cross domain substring",
host: "foo.com",
spiffeID: "spiffe://baz.foo.com.bar.com/stuff",
want: false,
}, {
name: "bad scheme",
host: "foo.com",
spiffeID: "https://bar.com/baz",
want: false,
}, {
name: "invalid url",
host: "foo.com",
spiffeID: "\nfoo",
want: false,
}}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isSpiffeIDAllowed(tt.host, tt.spiffeID); got != tt.want {
Expand Down

0 comments on commit bce3a8c

Please sign in to comment.