kiroauth

package
v4.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: AGPL-3.0 Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	BuilderIDStartURL = "https://view.awsapps.com/start"
	DefaultRegion     = "us-east-1"
)

Defaults for an AWS Builder ID login.

View Source
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

View Source
var ErrDeviceDenied = errors.New("the sign-in was denied in the browser")

ErrDeviceDenied means the user refused the sign-in in the browser.

View Source
var ErrDeviceExpired = errors.New("the sign-in code expired before it was approved")

ErrDeviceExpired means the code timed out before the user approved it.

View Source
var ErrReloginRequired = errors.New("the Kiro sign-in has expired; run `vulnetix ai-firewall kiro login` again")

ErrReloginRequired means the login can no longer mint tokens: the refresh token was rejected or the client registration expired.

View Source
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 `vulnetix 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.

View Source
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.

View Source
var Scopes = []string{
	"codewhisperer:completions",
	"codewhisperer:analysis",
	"codewhisperer:conversations",
}

Scopes are the CodeWhisperer scopes Kiro requests.

Functions

func APIBaseURL

func APIBaseURL(region string) string

APIBaseURL is the Kiro API endpoint for region.

func ARNRegion

func ARNRegion(arn string) string

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

func AllowedAPIURL(base string) bool

AllowedAPIURL reports whether an access token may be sent to base: an https Kiro API host, or a loopback origin (tests).

func AllowedOIDCURL

func AllowedOIDCURL(base string) bool

AllowedOIDCURL is AllowedAPIURL for the SSO-OIDC endpoint.

func CLIDatabasePaths

func CLIDatabasePaths(home string) []string

CLIDatabasePaths returns where kiro-cli keeps its database under home, most likely first.

func CachePath

func CachePath(home string) string

CachePath returns the Kiro IDE's token file under home.

func OIDCBaseURL

func OIDCBaseURL(region string) string

OIDCBaseURL is the SSO-OIDC endpoint for region.

func ProfilesBaseURL

func ProfilesBaseURL(region string) string

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

func ValidRegion(r string) bool

ValidRegion reports whether r looks like an AWS region name.

func ValidStartURL

func ValidStartURL(s string) bool

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.

func (DeviceLogin) Poll

func (d DeviceLogin) Poll(ctx context.Context, g Grant) (Login, error)

Poll waits for the user to approve g and returns the Login. It honours the service's interval, backs off on slow_down, and ends at the grant's expiry or ctx.

func (DeviceLogin) Start

func (d DeviceLogin) Start(ctx context.Context) (Grant, error)

Start registers a client and begins a device authorization.

type Endpoints

type Endpoints struct {
	OIDC     string
	Profiles []string
}

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.

func (Grant) BrowseURL

func (g Grant) BrowseURL() string

BrowseURL prefers the code-carrying URL so the user does not have to type.

func (Grant) GoString

func (g Grant) GoString() string

GoString never reveals the device code or the client secret.

func (Grant) String

func (g Grant) String() string

String never reveals the device code or the client secret.

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

func Import(home string) (Login, string, error)

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

func ParseLogin(s string) (Login, error)

ParseLogin decodes and validates a login.

func (Login) APIRegionOrDefault

func (l Login) APIRegionOrDefault() string

APIRegionOrDefault returns the Kiro API region: the explicit or profile-derived API region, else the SSO region, else us-east-1.

func (Login) Encode

func (l Login) Encode() string

Encode renders the login as the vault value.

func (Login) Expired

func (l Login) Expired(now time.Time) bool

Expired reports whether the client registration has expired.

func (Login) GoString

func (l Login) GoString() string

GoString never reveals the secrets.

func (Login) String

func (l Login) String() string

String never reveals the secrets.

func (Login) WithProfile

func (l Login) WithProfile(p Profile) Login

WithProfile records p in the login: its ARN, and its region as the Kiro API region.

type Profile

type Profile struct {
	ARN  string
	Name string
}

Profile is one CodeWhisperer profile the signed-in account can use.

func ListProfiles

func ListProfiles(ctx context.Context, client *http.Client, base, accessToken string) ([]Profile, error)

ListProfiles asks the CodeWhisperer service which profiles accessToken may use. base must pass AllowedAPIURL. Redirects are refused.

func (Profile) Region

func (p Profile) Region() string

Region returns the region the profile's ARN names, or "" when the ARN is malformed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL