44 lines
1.7 KiB
Go
44 lines
1.7 KiB
Go
|
|
package callerauth
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
// IR-WP-0004 / WARDEN-WP-0039: a caller binding is representation,
|
||
|
|
// not delegated authority over another system's credentials.
|
||
|
|
func TestOpenRouterNativeCallerBoundary(t *testing.T) {
|
||
|
|
bindings := map[string]string{
|
||
|
|
"ops-warden": "system:serviceaccount:ops-warden:ops-warden",
|
||
|
|
"secrets-engine": "system:serviceaccount:secrets-engine:secrets-engine",
|
||
|
|
}
|
||
|
|
for _, tc := range []struct {
|
||
|
|
name, caller string
|
||
|
|
systems []string
|
||
|
|
denied bool
|
||
|
|
}{
|
||
|
|
{"native lifecycle caller", bindings["secrets-engine"], []string{"secrets-engine"}, false},
|
||
|
|
{"warden own system", bindings["ops-warden"], []string{"ops-warden"}, false},
|
||
|
|
{"warden cannot represent custody owner", bindings["ops-warden"], []string{"railiance-platform"}, true},
|
||
|
|
{"warden cannot impersonate native engine", bindings["ops-warden"], []string{"secrets-engine"}, true},
|
||
|
|
{"radar is recipient not lifecycle caller", "system:serviceaccount:intelligence-radar:intelligence-radar", []string{"secrets-engine"}, true},
|
||
|
|
{"native caller cannot represent custody owner", bindings["secrets-engine"], []string{"railiance-platform"}, true},
|
||
|
|
{"batch must bind every owner", bindings["ops-warden"], []string{"ops-warden", "railiance-platform"}, true},
|
||
|
|
} {
|
||
|
|
t.Run(tc.name, func(t *testing.T) {
|
||
|
|
auth, err := New(ModeEnforce, fakeReviewer{identity: Identity{Username: tc.caller, Audiences: []string{"flex-auth"}}}, "flex-auth", bindings, nil)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
err = auth.Authorize(context.Background(), "Bearer synthetic-caller", tc.systems)
|
||
|
|
if tc.denied && !errors.Is(err, ErrForbidden) {
|
||
|
|
t.Fatalf("want forbidden, got %v", err)
|
||
|
|
}
|
||
|
|
if !tc.denied && err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|