Documentation
¶
Overview ¶
Package kiroauth signs in to Kiro with an AWS Builder ID or an IAM Identity Center start URL and produces the Kiro login the Vulnetix AI Firewall stores in the secrets vault for the kiro provider.
Kiro has no API key. A login is an AWS SSO-OIDC refresh token plus the client registration that minted it; the gateway trades it for a short-lived access token before each request. This package runs the device authorization grant itself (register a public client, start the device authorization, poll the token endpoint), or imports the sign-in Kiro's IDE or kiro-cli already holds.
The login's JSON shape is shared with belai (belai/internal/kiroauth), the vault (vdb-site handler/vault_kiro.go) and the gateway (ai-firewall/internal/kiroauth); the four must not drift.
Every token goes only to a pinned host: oidc.<region>.amazonaws.com and q.<region>.amazonaws.com or codewhisperer.<region>.amazonaws.com, over https and without redirects. The device code, client secret, refresh and access tokens are never rendered.
Index ¶
- Constants
- Variables
- func APIBaseURL(region string) string
- func ARNRegion(arn string) string
- func AllowedAPIURL(base string) bool
- func AllowedOIDCURL(base string) bool
- func CLIDatabasePaths(home string) []string
- func CachePath(home string) string
- func OIDCBaseURL(region string) string
- func ProfilesBaseURL(region string) string
- func ResolveProfile(ctx context.Context, client *http.Client, login Login, explicitARN string, ...) (Login, []Profile, error)
- func ValidRegion(r string) bool
- func ValidStartURL(s string) bool
- type DeviceLogin
- type Endpoints
- type Grant
- type Login
- type Profile
Constants ¶
const ( BuilderIDStartURL = "https://view.awsapps.com/start" DefaultRegion = "us-east-1" )
Defaults for an AWS Builder ID login.
const ClientName = "vulnetix-ai-firewall"
ClientName is the name the SSO-OIDC client registers under. The firewall gets its own registration, and so its own refresh token, rather than sharing the IDE's: a refresh token AWS rotates for one holder then never breaks the other.
Variables ¶
var ErrDeviceDenied = errors.New("the sign-in was denied in the browser")
ErrDeviceDenied means the user refused the sign-in in the browser.
var ErrDeviceExpired = errors.New("the sign-in code expired before it was approved")
ErrDeviceExpired means the code timed out before the user approved it.
var ErrReloginRequired = errors.New("the Kiro sign-in has expired; run `vulnesis ai-firewall kiro login` again")
ErrReloginRequired means the login can no longer mint tokens: the refresh token was rejected or the client registration expired.
var ErrSocialLogin = errors.New("Kiro is signed in with GitHub or Google; only AWS Builder ID and IAM Identity Center sign-ins can be used — run `vulnesis ai-firewall kiro login` without --import")
ErrSocialLogin means Kiro is signed in with GitHub or Google. Those logins refresh through Kiro's own auth service rather than AWS SSO-OIDC, so the gateway cannot use them.
var ProfileRegions = []string{"us-east-1", "eu-central-1"}
ProfileRegions are the regions Kiro is known to serve profiles from. The login's own API and SSO regions are always tried first.
var Scopes = []string{
"codewhisperer:completions",
"codewhisperer:analysis",
"codewhisperer:conversations",
}
Scopes are the CodeWhisperer scopes Kiro requests.
Functions ¶
func APIBaseURL ¶
APIBaseURL is the Kiro API endpoint for region.
func ARNRegion ¶
ARNRegion returns the region field of an arn:aws:codewhisperer ARN, or "" when it is not a well-formed CodeWhisperer ARN in a valid region.
func AllowedAPIURL ¶
AllowedAPIURL reports whether an access token may be sent to base: an https Kiro API host, or a loopback origin (tests).
func AllowedOIDCURL ¶
AllowedOIDCURL is AllowedAPIURL for the SSO-OIDC endpoint.
func CLIDatabasePaths ¶
CLIDatabasePaths returns where kiro-cli keeps its database under home, most likely first.
func OIDCBaseURL ¶
OIDCBaseURL is the SSO-OIDC endpoint for region.
func ProfilesBaseURL ¶
ProfilesBaseURL is the CodeWhisperer control endpoint for region.
func ResolveProfile ¶
func ResolveProfile(ctx context.Context, client *http.Client, login Login, explicitARN string, ep Endpoints) (Login, []Profile, error)
ResolveProfile settles the login's profile after a sign-in.
An explicit ARN wins and is only validated. A login that already names a profile (an import) keeps it. Otherwise the account's profiles are listed: with one, it is adopted; with none (a Builder ID account may have none) the login is returned unchanged; with several, they are returned for the caller to choose from with Login.WithProfile.
Listing mints a token, so the returned login carries whatever refresh token is current afterwards: it is the one to store.
func ValidRegion ¶
ValidRegion reports whether r looks like an AWS region name.
func ValidStartURL ¶
ValidStartURL reports whether s is an acceptable start URL: https with a host and no credentials.
Types ¶
type DeviceLogin ¶
type DeviceLogin struct {
// StartURL is the Builder ID or Identity Center start URL. Empty means the
// AWS Builder ID.
StartURL string
// Region is the SSO-OIDC region. Empty means us-east-1.
Region string
// APIRegion is the Kiro API region recorded in the login.
APIRegion string
// ProfileARN is recorded in the login for Identity Center accounts.
ProfileARN string
// BaseURL overrides the SSO-OIDC endpoint (tests); it must still pass
// AllowedOIDCURL.
BaseURL string
// Client makes the requests. Nil means a client with a short timeout.
Client *http.Client
// PollInterval is the minimum wait between polls. Zero means 5s.
PollInterval time.Duration
// SlowDown is added to the poll interval on slow_down. Zero means 5s.
SlowDown time.Duration
}
DeviceLogin runs the device authorization grant.
type Endpoints ¶
Endpoints overrides the hosts ResolveProfile talks to, for tests. Empty fields mean the real AWS hosts for the login's regions.
type Grant ¶
type Grant struct {
UserCode string
VerificationURI string
VerificationURIComplete string
ExpiresIn int
Interval int
// contains filtered or unexported fields
}
Grant is a started device sign-in. UserCode and the verification URLs are shown to the user; everything else is secret and never rendered.
type Login ¶
type Login struct {
RefreshToken string `json:"refresh_token"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
ClientSecretExpiresAt int64 `json:"client_secret_expires_at,omitempty"`
// Region is the SSO-OIDC region the login was made in.
Region string `json:"region"`
// StartURL is the Builder ID or IAM Identity Center start URL.
StartURL string `json:"start_url,omitempty"`
// APIRegion is the Kiro API region; empty means Region.
APIRegion string `json:"api_region,omitempty"`
// ProfileARN is the CodeWhisperer profile an Identity Center login sends
// with each request. A Builder ID login has none.
ProfileARN string `json:"profile_arn,omitempty"`
}
Login is everything needed to mint Kiro access tokens. It is secret as a whole: the refresh token and client secret are inside it.
func Import ¶
Import reads the Kiro sign-in under home: the Kiro IDE's AWS SSO cache first, then kiro-cli's database. It returns the login and the file it came from, or os.ErrNotExist (wrapped) when neither has signed in.
func Mint ¶
func Mint(ctx context.Context, client *http.Client, login Login, oidcBase string) (accessToken string, current Login, err error)
Mint trades login for an access token. It returns the login to keep: the same one, or one carrying the new refresh token when the service rotated it. oidcBase overrides the SSO-OIDC endpoint (tests); empty means the login's region.
func ParseLogin ¶
ParseLogin decodes and validates a login.
func (Login) APIRegionOrDefault ¶
APIRegionOrDefault returns the Kiro API region: the explicit or profile-derived API region, else the SSO region, else us-east-1.
func (Login) WithProfile ¶
WithProfile records p in the login: its ARN, and its region as the Kiro API region.
type Profile ¶
Profile is one CodeWhisperer profile the signed-in account can use.