Documentation
¶
Index ¶
- Constants
- Variables
- func FilePermissionRemediationCommand(path string) (command string, safe bool)
- func FixPrivateKeyFilePermissions(path string) (bool, error)
- func GetCredentials(profile string) (*config.Config, error)
- func GetCredentialsWithSource(profile string) (*config.Config, string, error)
- func GetDefaultCredentials() (*config.Config, error)
- func KeychainAvailable() (bool, error)
- func LoadPrivateKey(path string) (*ecdsa.PrivateKey, error)
- func LoadPrivateKeyFromPEM(data []byte) (*ecdsa.PrivateKey, error)
- func LoadValidatedPrivateKey(path string) (*ecdsa.PrivateKey, error)
- func LooksLikeIssuerID(value string) bool
- func LooksLikeKeyID(value string) bool
- func NormalizePrivateKeyPEM(value string) string
- func ReadValidatedKeyFile(path string) ([]byte, error)
- func RemoveAllCredentialsWithOptions(opts RemoveOptions) error
- func RemoveCredentialsWithOptions(name string, opts RemoveOptions) error
- func ResetInvalidBypassKeychainWarningsForTest()
- func RetainedGlobalConfigCredentials(name string) (string, bool, error)
- func SetDefaultCredentials(name string) error
- func ShouldBypassKeychain() bool
- func StoreCredentialsConfigAt(name, keyID, issuerID, keyPath, configPath string) error
- func StoreCredentialsConfigAtWithKeyType(name, keyID, issuerID, keyPath, configPath, keyType string) error
- func StoreCredentialsConfigWithKeyType(name, keyID, issuerID, keyPath, keyType string) error
- func StoreCredentialsPEMConfigAtWithKeyType(name, keyID, issuerID, privateKeyPEM, configPath, keyType string) (string, error)
- func StoreCredentialsPEMWithKeyType(name, keyID, issuerID, privateKeyPEM, keyType string) (string, error)
- func StoreCredentialsWithKeyType(name, keyID, issuerID, keyPath, keyType string) error
- func ValidateKeyFile(path string) error
- type Credential
- type CredentialShapeFinding
- type CredentialShapeLabels
- type Credentials
- type CredentialsWarning
- type DoctorCheck
- type DoctorMigrationHints
- type DoctorOptions
- type DoctorReport
- type DoctorSection
- type DoctorStatus
- type DoctorSummary
- type InvalidKeychainEntryError
- type MigrateKeychainToConfigOptions
- type MigrateKeychainToConfigResult
- type MigratedCredential
- type MigrationSuggestionResolver
- type MigrationSuggestionResolverInput
- type MigrationSuggestionResolverOutput
- type PrivateKeyError
- type PrivateKeyErrorKind
- type PrivateKeyFileFix
- type RemoveOptions
Constants ¶
const APIKeysURL = "https://appstoreconnect.apple.com/access/integrations/api"
APIKeysURL is where App Store Connect API keys are created.
const LoginCommandExample = "asc auth login --name MyKey --key-id KEY_ID --issuer-id ISSUER_ID --private-key /path/to/AuthKey_KEY_ID.p8"
LoginCommandExample is a complete auth login invocation for a team key.
Variables ¶
var ErrDefaultCredentialsNotFound = errors.New("default credentials not found")
ErrDefaultCredentialsNotFound indicates that stored credentials exist, but no default selection resolves for the current no-profile lookup.
var ErrKeychainAccessDenied = errors.New("keychain access denied")
ErrKeychainAccessDenied is returned when a keychain backend is available but access is explicitly denied (e.g. user clicked "Deny" on the prompt).
This is distinct from keychain being unavailable (`keyring.ErrNoAvailImpl`).
var ErrKeychainReadFailed = errors.New("keychain read failed")
ErrKeychainReadFailed is returned when a keychain backend is available but reading stored credentials from it fails for any other reason.
var ErrProfileNotFound = errors.New("credentials not found")
ErrProfileNotFound indicates that no stored credentials match the selected profile name.
Functions ¶
func FilePermissionRemediationCommand ¶
FilePermissionRemediationCommand returns the exact command an operator can run to tighten an over-permissive credential file. Callers print it so a failed read names the one command that repairs the file, and so the recommendation text never drifts between `auth doctor` and `auth login`.
The path is quoted for a POSIX shell, so a path holding metacharacters such as `$(...)`, a backtick, or `$VAR` is pasted literally instead of being expanded, and a leading dash is anchored so chmod reads it as a file rather than a flag. A path carrying control or display-reordering characters cannot be rendered as a trustworthy copy-paste command, so callers receive safe=false and must offer a command that does not embed the path.
func FixPrivateKeyFilePermissions ¶
FixPrivateKeyFilePermissions tightens an over-permissive private key file to 0600 using the same rule ValidateKeyFile and `auth doctor` apply, and reports whether the mode changed so callers can tell the operator what was altered. A file that is already owner-only is left exactly as it is. The mode is applied through the rooted traversal used elsewhere for operator-selected paths, so a symlinked component, a directory, or any other non-regular file is rejected instead of being changed. Platforms that cannot securely open a key which denies its owner read access fail closed. Failures carry PrivateKeyError kinds, keeping the existing private-key diagnostics.
func GetCredentials ¶
GetCredentials returns credentials for a named profile.
func GetCredentialsWithSource ¶
GetCredentialsWithSource returns credentials for a named profile along with the source.
func GetDefaultCredentials ¶
GetDefaultCredentials returns the default credentials.
func KeychainAvailable ¶
KeychainAvailable reports whether a system keychain backend is available.
func LoadPrivateKey ¶
func LoadPrivateKey(path string) (*ecdsa.PrivateKey, error)
LoadPrivateKey loads the private key from the file
func LoadPrivateKeyFromPEM ¶
func LoadPrivateKeyFromPEM(data []byte) (*ecdsa.PrivateKey, error)
LoadPrivateKeyFromPEM loads an ECDSA private key from PEM bytes.
func LoadValidatedPrivateKey ¶
func LoadValidatedPrivateKey(path string) (*ecdsa.PrivateKey, error)
LoadValidatedPrivateKey checks the key file's permissions and parses the key from the same open file.
func LooksLikeIssuerID ¶ added in v1.260822.0
LooksLikeIssuerID reports whether value has the App Store Connect issuer ID shape: a canonical hyphenated UUID such as 69a6de00-aaaa-bbbb-cccc-123456789abc. Non-canonical spellings accepted by uuid.Parse (braced, URN, unhyphenated) are rejected because Apple only ever issues the canonical form.
func LooksLikeKeyID ¶ added in v1.260822.0
LooksLikeKeyID reports whether value has the App Store Connect API key ID shape: a short uppercase alphanumeric identifier such as 39MX87M9Y4. A false result never means the value is invalid; it only means the value carries no evidence of being a key ID.
func NormalizePrivateKeyPEM ¶
NormalizePrivateKeyPEM restores the line structure that CI secret stores and shells strip from an inline key: escaped newlines, a key flattened onto one line, or a body whose BEGIN and END lines were dropped. A value it cannot repair is returned with only its escaped newlines replaced, so that key parsing reports it.
func ReadValidatedKeyFile ¶
ReadValidatedKeyFile reads a file holding private key material after the same checks ValidateKeyFile applies before it parses a key file.
func RemoveAllCredentialsWithOptions ¶
func RemoveAllCredentialsWithOptions(opts RemoveOptions) error
RemoveAllCredentialsWithOptions removes all stored credentials from the keychain and the config files that opts selects. ASC_BYPASS_KEYCHAIN leaves the keychain untouched.
func RemoveCredentialsWithOptions ¶
func RemoveCredentialsWithOptions(name string, opts RemoveOptions) error
RemoveCredentialsWithOptions removes a named credential from the keychain and the config files that opts selects.
func ResetInvalidBypassKeychainWarningsForTest ¶ added in v1.260325.0
func ResetInvalidBypassKeychainWarningsForTest()
ResetInvalidBypassKeychainWarningsForTest clears cached invalid-bypass warnings for tests.
func RetainedGlobalConfigCredentials ¶
RetainedGlobalConfigCredentials reports whether the global config (~/.asc/config.json) holds credentials that removal with the default RemoveOptions leaves in place because ASC_CONFIG_PATH selects another file. An empty name matches any stored credential. It returns the global config path when such credentials exist.
func SetDefaultCredentials ¶
SetDefaultCredentials sets the default profile name for credential resolution.
func ShouldBypassKeychain ¶
func ShouldBypassKeychain() bool
ShouldBypassKeychain reports whether keychain usage is disabled via env.
func StoreCredentialsConfigAt ¶
StoreCredentialsConfigAt stores credentials in the specified config file.
func StoreCredentialsConfigAtWithKeyType ¶ added in v1.260613.0
func StoreCredentialsConfigAtWithKeyType(name, keyID, issuerID, keyPath, configPath, keyType string) error
StoreCredentialsConfigAtWithKeyType stores credentials in the specified config file with an explicit key type.
func StoreCredentialsConfigWithKeyType ¶ added in v1.260613.0
StoreCredentialsConfigWithKeyType stores credentials in the config file only with an explicit key type. It writes to ASC_CONFIG_PATH when set, matching where reads look, and otherwise to the global config.
func StoreCredentialsPEMConfigAtWithKeyType ¶
func StoreCredentialsPEMConfigAtWithKeyType(name, keyID, issuerID, privateKeyPEM, configPath, keyType string) (string, error)
StoreCredentialsPEMConfigAtWithKeyType stores credentials whose private key is PEM text in the specified config file, writing the PEM to the keys directory beside it, and returns the path of that key file.
func StoreCredentialsPEMWithKeyType ¶
func StoreCredentialsPEMWithKeyType(name, keyID, issuerID, privateKeyPEM, keyType string) (string, error)
StoreCredentialsPEMWithKeyType stores credentials whose private key is PEM text rather than a file. The keychain keeps the PEM itself. When the credentials go to a config file instead, the PEM is written to the keys directory beside it and its path is returned; otherwise the path is empty.
func StoreCredentialsWithKeyType ¶ added in v1.260613.0
StoreCredentialsWithKeyType stores credentials with an explicit App Store Connect key type.
func ValidateKeyFile ¶
ValidateKeyFile validates that the private key file exists and is valid
Types ¶
type Credential ¶
type Credential struct {
Name string `json:"name"`
KeyID string `json:"key_id"`
IssuerID string `json:"issuer_id"`
PrivateKeyPath string `json:"private_key_path"`
PrivateKeyPEM string `json:"-"`
KeyType string `json:"key_type,omitempty"`
IsDefault bool `json:"is_default"`
Source string `json:"source,omitempty"`
SourcePath string `json:"source_path,omitempty"`
MetadataNeedsBackfill bool `json:"-"`
MetadataModifiedAt time.Time `json:"-"`
}
Credential represents stored API credentials
func ListCredentialSummaries ¶
func ListCredentialSummaries() ([]Credential, error)
ListCredentialSummaries lists stored credentials without reading key material when the active keyring backend exposes non-secret metadata.
func ListCredentials ¶
func ListCredentials() ([]Credential, error)
ListCredentials lists all stored credentials from all sources. Credentials are merged from keychain and config, with keychain taking precedence when the same name exists in both sources.
type CredentialShapeFinding ¶ added in v1.260822.0
type CredentialShapeFinding struct {
Field string
Message string
Recommendation string
// DefiniteSwap marks the only unambiguous case: the key ID is an issuer
// UUID and the issuer ID also resembles an API key ID.
DefiniteSwap bool
}
CredentialShapeFinding is a non-blocking observation about the shape of a key ID or issuer ID. Messages never include the inspected values so reports stay safe to paste into a bug report or CI log.
func InspectCredentialShapes ¶ added in v1.260822.0
func InspectCredentialShapes(labels CredentialShapeLabels, keyID, issuerID string) []CredentialShapeFinding
InspectCredentialShapes reports key ID and issuer ID values whose shapes suggest the two were swapped, or an issuer ID that cannot be a UUID.
Only the issuer ID has a format Apple guarantees, so key IDs are never format-policed: an unusual but plausible key ID (all digits, mixed case, shorter or longer than 10 characters) produces no finding. The key ID is flagged only when it is itself a canonical UUID, which is the shape of the other field.
type CredentialShapeLabels ¶ added in v1.260822.0
CredentialShapeLabels names the fields being inspected so findings speak in the caller's vocabulary: environment variables for `auth doctor`, flags for `auth login`.
type Credentials ¶
type Credentials struct {
DefaultKey string `json:"default_key"`
Keys []Credential `json:"keys"`
}
Credentials stores multiple credentials
type CredentialsWarning ¶
type CredentialsWarning struct {
// contains filtered or unexported fields
}
CredentialsWarning indicates that some credential sources could not be read. Credentials returned alongside the warning are still usable.
func (*CredentialsWarning) Error ¶
func (w *CredentialsWarning) Error() string
func (*CredentialsWarning) Unwrap ¶
func (w *CredentialsWarning) Unwrap() error
type DoctorCheck ¶
type DoctorCheck struct {
Status DoctorStatus `json:"status"`
Message string `json:"message"`
Recommendation string `json:"recommendation,omitempty"`
FixApplied bool `json:"fix_applied,omitempty"`
}
type DoctorMigrationHints ¶
type DoctorOptions ¶
type DoctorReport ¶
type DoctorReport struct {
Sections []DoctorSection `json:"sections"`
Summary DoctorSummary `json:"summary"`
Recommendations []string `json:"recommendations,omitempty"`
Migration *DoctorMigrationHints `json:"migration,omitempty"`
}
func Doctor ¶
func Doctor(options DoctorOptions) DoctorReport
func DoctorWithMigrationResolver ¶
func DoctorWithMigrationResolver(options DoctorOptions, resolver MigrationSuggestionResolver) DoctorReport
type DoctorSection ¶
type DoctorSection struct {
Title string `json:"title"`
Checks []DoctorCheck `json:"checks"`
}
type DoctorStatus ¶
type DoctorStatus string
const ( DoctorOK DoctorStatus = "ok" DoctorWarn DoctorStatus = "warn" DoctorFail DoctorStatus = "fail" DoctorInfo DoctorStatus = "info" )
type DoctorSummary ¶
type InvalidKeychainEntryError ¶
type InvalidKeychainEntryError struct {
// Key is the keychain item key; Name is the profile it stores.
Key string
Name string
Err error
}
InvalidKeychainEntryError reports a stored credential whose keychain item the process could read but not decode. It is a corrupt entry, not a keychain the process cannot read, so it is not marked ErrKeychainReadFailed by the listings.
func (*InvalidKeychainEntryError) Error ¶
func (e *InvalidKeychainEntryError) Error() string
func (*InvalidKeychainEntryError) Unwrap ¶
func (e *InvalidKeychainEntryError) Unwrap() error
type MigrateKeychainToConfigOptions ¶ added in v1.260610.0
type MigrateKeychainToConfigOptions struct {
ConfigPath string
PrivateKeyDir string
RemoveKeychain bool
}
MigrateKeychainToConfigOptions controls keychain-to-config migration.
type MigrateKeychainToConfigResult ¶ added in v1.260610.0
type MigrateKeychainToConfigResult struct {
ConfigPath string `json:"configPath"`
PrivateKeyDir string `json:"privateKeyDir,omitempty"`
Migrated []MigratedCredential `json:"migrated"`
RemovedFromKeychain bool `json:"removedFromKeychain"`
Warnings []string `json:"warnings,omitempty"`
}
MigrateKeychainToConfigResult summarizes a keychain-to-config migration.
func MigrateKeychainToConfig ¶ added in v1.260610.0
func MigrateKeychainToConfig(opts MigrateKeychainToConfigOptions) (MigrateKeychainToConfigResult, error)
MigrateKeychainToConfig copies keychain-backed credentials into config.json.
If a keychain entry contains embedded PEM data and its original private key path is missing, the PEM is exported to a secure .p8 file and config.json is updated to reference that file.
type MigratedCredential ¶ added in v1.260610.0
type MigratedCredential struct {
Name string `json:"name"`
KeyID string `json:"keyId"`
PrivateKeyPath string `json:"privateKeyPath"`
ExportedPrivateKey bool `json:"exportedPrivateKey,omitempty"`
// contains filtered or unexported fields
}
MigratedCredential reports one profile copied into config.json.
type MigrationSuggestionResolver ¶
type MigrationSuggestionResolver func(input MigrationSuggestionResolverInput) MigrationSuggestionResolverOutput
type PrivateKeyError ¶ added in v1.260819.0
type PrivateKeyError struct {
Kind PrivateKeyErrorKind
// contains filtered or unexported fields
}
PrivateKeyError preserves the existing user-facing error while carrying a bounded reason that CLI diagnostics can classify without parsing text.
func (*PrivateKeyError) Error ¶ added in v1.260819.0
func (e *PrivateKeyError) Error() string
func (*PrivateKeyError) Unwrap ¶ added in v1.260819.0
func (e *PrivateKeyError) Unwrap() error
type PrivateKeyErrorKind ¶ added in v1.260819.0
type PrivateKeyErrorKind string
PrivateKeyErrorKind classifies private-key failures without exposing key material or filesystem paths to callers that only need recovery metadata.
const ( PrivateKeyNotFound PrivateKeyErrorKind = "not_found" PrivateKeyPermissionDenied PrivateKeyErrorKind = "permission_denied" PrivateKeyPermissionsInsecure PrivateKeyErrorKind = "permissions_insecure" PrivateKeyInvalidFormat PrivateKeyErrorKind = "invalid_format" PrivateKeyUnsupportedAlgorithm PrivateKeyErrorKind = "unsupported_algorithm" PrivateKeyAccessFailed PrivateKeyErrorKind = "access_failed" )
func PrivateKeyErrorKindOf ¶ added in v1.260819.0
func PrivateKeyErrorKindOf(err error) (PrivateKeyErrorKind, bool)
PrivateKeyErrorKindOf returns the structured kind carried by err.
type PrivateKeyFileFix ¶
type PrivateKeyFileFix struct {
// Mode is the file's current permission bits.
Mode fs.FileMode
// CanChangeMode is false when another user owns the file and the caller
// is not root, so neither chmod nor --fix-permissions can change it until
// its owner changes. Root can change any file's mode.
CanChangeMode bool
// Commands repair the file in order. It is empty when the path cannot be
// rendered as a trustworthy copy-paste command.
Commands []string
}
PrivateKeyFileFix describes how to make a refused private key file readable by its user alone.
func PrivateKeyFileFixFor ¶
func PrivateKeyFileFixFor(path string) (PrivateKeyFileFix, error)
PrivateKeyFileFixFor inspects the key file at path, without changing it, and returns the commands that give the current user sole read and write access.
type RemoveOptions ¶
type RemoveOptions struct {
// IncludeGlobalConfig also removes matching credentials from the global
// config (~/.asc/config.json) when ASC_CONFIG_PATH selects another file.
// Without ASC_CONFIG_PATH the global config is always included.
IncludeGlobalConfig bool
}
RemoveOptions controls which config files credential removal edits.