* Fix down migrations * Udpates due to merge * Sentinel values only have to be greater than 0 * Create credential related sdk structs and methods. * Post merge interface updating. * Removing scratch code that was not cleaned up. * updates * Convert client certificate and client certificate keys into pem blocks and validate. * Add newline at end of file. * Faster check for "s" at the end of a resource name when generating from templates. * make fmt * updates * Add dynamic credentials to a session * Refactor: move contents of file * updates * Updates * Add InvalidDynamicCredential error * Assign credentials * Allow updating client certificates seperate from the client certificate key. * Replace application purpose string with enum value * PR feedback / fix go test . * Delete dead code * Use common view * Refactor: extract interface and rename method * Refactor: move code to eliminate privPurpLibrary * Add comment to requestMap * Refactor: do not export methods on an unexported struct * Update internal/db/schema/migrations/postgres/10/03_vault_credential.up.sql Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> * Add comments to credential Purpose constants * Reorder switch statements to handle errors first * PR feedback * update * fix merge * Organizing the scheduler code and extract the individual store creation test helper function. * Run 'make fmt' * Create certificate when creating store. Allow vault address to be passed in as option * Refactor: rename database views and associated structs This change renames two database views and associated go structs to use a consistent naming pattern. Views ending in 'private' contain encrypted credentials needed for connecting to Vault. Views ending in 'public' mirror the 'private' views but do not include any encrypted values. This change does not include any changes to functionality or behavior. * Adding SAD target operations for credential libraries to the SDK. * Add status field and enumeration table for credential status * Refactor: rename Status to TokenStatus * Add status to vault credentials * Creating the template for the CLI and helper functions. * Add private database view for vault credentials * Add scope_id to view and cleanup TODO comment * Reformat embedded sql queries * Add vault client helpers * updates * white space * Add LookupLease test * CLI commands for Store work. Renamed fields in proto w/ vault prefix. * Test issue credentials with client TLS * Add additional checks to vault ping * Add an error for vault token capabilities and create a VaultToken error kind * Add support for working with Vault policies * Use Vault 1.7.2 for testing * Add testing helper for creating a vault client with a non-root token * Fix Vault renew lease test The Vault renew lease endpoint accepts an optional duration parameter for requesting the number of seconds to extend the lease by. However, Vault is not required to honor this request. * Add a var for the required capabilities of a boundary Vault token * Enhance the test helper for adding a policy to Vault * Allow the test role in postgresql to revoke credentials * Remove out of date comments * Enhance Vault test helpers for the database secrets engine * Reformat comments * Add a method for getting the capabilities of the current Vault token * Add revoke lease to internal Vault client * Reformat: combine err return line with check for nil line * Remove redundant checks in test code Remove checks in test code that are redundant with checks in the test harness. * Refactor CreateToken test helper to return the secret and the token * Fix build failures caused by signature change in vault.CreateToken * Fix Vault version and Vault API link in comments * ran `make gen` after merging from mgaffney-vault. * Remove Vault prefix from attribute fields in API, create a base CLI option for adding field prefixes. format now uses that prefix for error reporting. * Template now allows attaching attribute field prefixes. * Credential store uses PrefixAttributeFieldErrorsWithSubactionPrefix. * Fixing naming of vault flags and helper flags. * Updating more references to generated api methods. * Make the capabilities String method more readable * Add comment outlining PrintApiError usage of Options. * Refactor test to move declarations closer to first use * Fix comment * Implement revoke method on vault repository * Tests now verify certs, CA, and tokens, addresses can be updated in a store. * Added test for creating store with pk/cert in same field. * Allo updating certificates seperate from private key. Only contact backing vault service when updating token. * Fixing bad tests and removing unused code. * Adding tests for various ways of updating tokens. * Add private credential * Add token revocation job and cred renewal/revocation job * Regen after merge. * Fixing field mask related merge error. * Create Library CLI. Removes vault prefix from path. Adds a WithoutCleanup testOption for vault. * Set all credentials to revoked when a token is revoked * Fixing missed renaming update. * fix copy/paste error. * Fixing code generation errors after merge. * make gen after merge. * Update internal/cmd/commands/credentialstorescmd/vault_funcs.go Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> * Update internal/cmd/commands/credentialstorescmd/vault_funcs.go Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> * Update internal/cmd/commands/credentialstorescmd/vault_funcs.go Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> * Refactor: move migrations from 10 to 12 * Removing logic from transaction. * wrapping client errors in the calling op for CredentialStore's client() method. * Redact token * redact client key * updates * Add trigger to revoke credentials when session is canceled or terminated * Fixing some help text for some flags. * Add ability to load values from files (file://) or environment variables (env://). * Updating comments * fix bad merge * feedback * Adding issued credentials to sessions. * Error on capabilities * updates * Expose NewVaulTestServer * Add godoc * Adding generated SessionCredential struct for API. * Progress on building handler test for Authorize Session. * feedback * Update policies * Add 'revoke' as a status for Vault Tokens * Add delete_time to vault credential store * Create dynamic credentials at session creation time. * Tests pass with credentials attached to AuthorizedSession result. * Only call issue if there are credentials to issue. * Fixing output only issues. Adding type to credential library. * Fix test to clear un/pw generated. confirm generated un/pw changes from 1 authorize session call to another. * Update lookupTokenError * Add delete_time to private credential store * Refactor: move private store to separate file * Fixing tests for AuthorizeSession and verifying error cases. * Only create the credential repo if there are credentials to issue. * Rename Library field to CredentialLibrary. * Fixing missing change of Library to CredentialLibrary. * Removing Default SDK functions for fields which are required and update CLI to match. * Replace resource specific id variables with "id" and the input parmater for paths to be just a single string and the resource name as it should show up in the path. * Soft delete vault credential stores * Prevent new SQL functions from silently overwriting existing functions * Rename "Hmac" to "HMAC" in the human readable cli response table. * Fix tests * Add vault database cleanup jobs * Add ability to set the token period in the vault test harness * updates * Add not_null_columns func test * remove unused struct * Up no output timeout * Validate current vault token on addr update * Fix client cert change test * add cert test * Update revocation job where * Fix comment * Use Vault's default port in CLI help strings * Remove down migrations * Increase migration file numbers by 1 * Run make migrations * Move migrations from 12 to 10 * Increase Circle CI timeout for acceptance tests * Fix spelling mistake in error messages * ASD cmds for Target and returning credentials to AuthSession request (#1338) * Add Add/Set/Remove commands for libraries on Targets. Return credentials on AuthorizeSession request. Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> Co-authored-by: Louis Ruch <louisruch@gmail.com> Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com> Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
107 lines
7.0 KiB
Go
107 lines
7.0 KiB
Go
package errors
|
|
|
|
// Code specifies a code for the error.
|
|
type Code uint32
|
|
|
|
// String will return the Code's Info.Message
|
|
func (c Code) String() string {
|
|
return c.Info().Message
|
|
}
|
|
|
|
// Info will look up the Code's Info. If the Info is not found, it will return
|
|
// Info for an Unknown Code.
|
|
func (c Code) Info() Info {
|
|
if info, ok := errorCodeInfo[c]; ok {
|
|
return info
|
|
}
|
|
return errorCodeInfo[Unknown]
|
|
}
|
|
|
|
const (
|
|
Unknown Code = 0 // Unknown will be equal to a zero value for Codes
|
|
|
|
// General function errors are reserved Codes 100-999
|
|
InvalidParameter Code = 100 // InvalidParameter represents an invalid parameter for an operation.
|
|
InvalidAddress Code = 101 // InvalidAddress represents an invalid host address for an operation
|
|
InvalidPublicId Code = 102 // InvalidPublicId represents an invalid public Id for an operation
|
|
InvalidFieldMask Code = 103 // InvalidFieldMask represents an invalid field mast for an operation
|
|
EmptyFieldMask Code = 104 // EmptyFieldMask represents an empty field mask for an operation
|
|
KeyNotFound Code = 105 // KeyNotFound represents that a key/version was not found in the KMS
|
|
TicketAlreadyRedeemed Code = 106 // TicketAlreadyRedeemed represents that the ticket version has already been redeemed
|
|
TicketNotFound Code = 107 // TicketNotFound represents that the ticket was not found
|
|
Io Code = 108 // Io represents that an io error occurred in an underlying call (i.e binary.Write)
|
|
InvalidTimeStamp Code = 109 // InvalidTimeStamp represents an invalid time stamp for an operation
|
|
SessionNotFound Code = 110 // SessionNotFound represents that the session was not found
|
|
InvalidSessionState Code = 111 // InvalidSessionState represents that the session was in an invalid state
|
|
TokenMismatch Code = 112 // TokenMismatch represents that there was a token mismatch
|
|
TooShort Code = 113 // TooShort represents an error that means the provided input is not meeting minimum length requirements
|
|
AccountAlreadyAssociated Code = 114 // AccountAlreadyAssociated represents an attempt to associate an account failed since it was already associated.
|
|
InvalidJobRunState Code = 115 // InvalidJobRunState represents that a JobRun was in an invalid state
|
|
InvalidDynamicCredential Code = 116 // InvalidDynamicCredential represents that a dynamic credential for a session was in an invalid state
|
|
JobAlreadyRunning Code = 117 // JobAlreadyRunning represents that a Job is already running when an attempt to run again was made
|
|
|
|
AuthAttemptExpired Code = 198 // AuthAttemptExpired represents an expired authentication attempt
|
|
AuthMethodInactive Code = 199 // AuthMethodInactive represents an error that means the auth method is not active.
|
|
|
|
// PasswordTooShort results from attempting to set a password which is to short.
|
|
PasswordTooShort Code = 200
|
|
|
|
// PasswordUnsupportedConfiguration results from attempting to perform an
|
|
// operation that sets a password configuration to an unsupported type.
|
|
PasswordUnsupportedConfiguration Code = 201
|
|
|
|
// PasswordInvalidConfiguration results from attempting to perform an
|
|
// operation that sets a valid password configuration with invalid settings.
|
|
PasswordInvalidConfiguration Code = 202
|
|
|
|
// PasswordsEqual is returned from ChangePassword when the old and
|
|
// new passwords are equal.
|
|
PasswordsEqual Code = 203
|
|
|
|
Encrypt Code = 300 // Encrypt represents an error occurred during the underlying encryption process
|
|
Decrypt Code = 301 // Decrypt represents an error occurred during the underlying decryption process
|
|
Encode Code = 302 // Encode represents an error occurred during the underlying encoding/marshaling process
|
|
Decode Code = 303 // Decode represents an error occurred during the underlying decoding/unmarshaling process
|
|
GenKey Code = 304 // GenKey represents an error occurred during the underlying key generation process
|
|
GenCert Code = 305 // GenCert represents an error occurred during the underlying certificate generation process
|
|
|
|
// General system errors are reserved Codes 400-599 and align with http client and server error codes
|
|
Forbidden Code = 403 // Forbidden represents the operation is forbidden
|
|
Internal Code = 500 // InternalError represents the system encountered an unexpected condition.
|
|
|
|
// DB errors are reserved Codes from 1000-1999
|
|
CheckConstraint Code = 1000 // CheckConstraint represents a check constraint error
|
|
NotNull Code = 1001 // NotNull represents a value must not be null error
|
|
NotUnique Code = 1002 // NotUnique represents a value must be unique error
|
|
NotSpecificIntegrity Code = 1003 // NotSpecificIntegrity represents an integrity error that has no specific domain error code
|
|
MissingTable Code = 1004 // MissingTable represents an undefined table error
|
|
RecordNotFound Code = 1100 // RecordNotFound represents that a record/row was not found matching the criteria
|
|
MultipleRecords Code = 1101 // MultipleRecords represents that multiple records/rows were found matching the criteria
|
|
ColumnNotFound Code = 1102 // ColumnNotFound represent that a column was not found in the underlying db
|
|
MaxRetries Code = 1103 // MaxRetries represent that a db Tx hit max retires allowed
|
|
Exception Code = 1104 // Exception represent that an underlying db exception was raised
|
|
VersionMismatch Code = 1105 // VersionMismatch represents the update version and the db version for an entry do not match.
|
|
// GracefullyAborted means we intended to abort a transaction but the
|
|
// enclosing function should not treat it as an error; we aborted for
|
|
// reasons related to the state of the DDL and/or inputs (such as we're
|
|
// already in the right state and don't want to end up writing oplogs).
|
|
GracefullyAborted Code = 1106
|
|
|
|
// Migration setup errors are codes 2000-2999
|
|
MigrationIntegrity Code = 2000 // MigrationIntegrity represents an error with the generated migration related code
|
|
MigrationLock Code = 2001 // MigrationLock represents an error related to locking of the DB
|
|
|
|
// External system errors are reserved codes 3000-3999
|
|
Unavailable Code = 3000 // Unavailable represents that an external system is unavailable
|
|
|
|
// Vault specific errors
|
|
VaultTokenNotOrphan Code = 3010 // VaultTokenNotOrphan represents an error for a Vault token that is not an orphan token
|
|
VaultTokenNotPeriodic Code = 3011 // VaultTokenNotPeriodic represents an error for a Vault token that is not a periodic token
|
|
VaultTokenNotRenewable Code = 3012 // VaultTokenNotRenewable represents an error for a Vault token that is not renewable
|
|
VaultTokenMissingCapabilities Code = 3013 // VaultTokenMissingCapabilities represents an error for a Vault token that is missing capabilities
|
|
VaultCredentialRequest Code = 3014 // VaultCredentialRequest represents an error returned from Vault when retrieving a credential
|
|
|
|
// OIDC authentication provided errors
|
|
OidcProviderCallbackError Code = 4000 // OidcProviderCallbackError represents an error that is passed by the OIDC provider to the callback endpoint
|
|
)
|