Documentation ¶
Index ¶
- Constants
- Variables
- func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error)
- func GitlabClientNewContext(ctx context.Context, client Client) context.Context
- func HttpClientFromContext(ctx context.Context) (*http.Client, bool)
- func HttpClientNewContext(ctx context.Context, httpClient *http.Client) context.Context
- func TimeFromContext(ctx context.Context) time.Time
- func TokenName(role *EntryRole) (name string, err error)
- func WithStaticTime(ctx context.Context, t time.Time) context.Context
- type AccessLevel
- type Backend
- type Client
- type EntryConfig
- type EntryRole
- type EntryToken
- type TokenScope
- type TokenType
- type Type
Constants ¶
View Source
const ( DefaultConfigFieldAccessTokenMaxTTL = 7 * 24 * time.Hour DefaultConfigFieldAccessTokenRotate = DefaultAutoRotateBeforeMinTTL DefaultRoleFieldAccessTokenMaxTTL = 24 * time.Hour DefaultAccessTokenMinTTL = 24 * time.Hour DefaultAccessTokenMaxPossibleTTL = 365 * 24 * time.Hour DefaultAutoRotateBeforeMinTTL = 24 * time.Hour DefaultAutoRotateBeforeMaxTTL = 730 * time.Hour DefaultConfigName = "default" )
View Source
const ( PathRoleStorage = "roles" TypeConfigDefault = DefaultConfigName )
View Source
const ( AccessLevelNoPermissions = AccessLevel("no_permissions") AccessLevelMinimalAccessPermissions = AccessLevel("minimal_access") AccessLevelGuestPermissions = AccessLevel("guest") AccessLevelReporterPermissions = AccessLevel("reporter") AccessLevelDeveloperPermissions = AccessLevel("developer") AccessLevelMaintainerPermissions = AccessLevel("maintainer") AccessLevelOwnerPermissions = AccessLevel("owner") AccessLevelUnknown = AccessLevel("") )
View Source
const ( // TokenScopeApi grants complete read and write access to the scoped group and related project API, including the Package Registry TokenScopeApi = TokenScope("api") // TokenScopeReadApi grants read access to the scoped group and related project API, including the Package Registry TokenScopeReadApi = TokenScope("read_api") // TokenScopeReadRegistry grants read access (pull) to the Container Registry images if any project within expected group is private and authorization is required. TokenScopeReadRegistry = TokenScope("read_registry") // TokenScopeWriteRegistry grants write access (push) to the Container Registry. TokenScopeWriteRegistry = TokenScope("write_registry") // TokenScopeReadRepository grants read access (pull) to the Container Registry images if any project within expected group is private and authorization is required TokenScopeReadRepository = TokenScope("read_repository") // TokenScopeWriteRepository grants read and write access (pull and push) to all repositories within expected group TokenScopeWriteRepository = TokenScope("write_repository") // TokenScopeCreateRunner grants permission to create runners in expected group TokenScopeCreateRunner = TokenScope("create_runner") // TokenScopeManageRunner grants permission to manage runners in expected group TokenScopeManageRunner = TokenScope("manage_runner") // TokenScopeReadUser grants read-only access to the authenticated user’s profile through the /user API endpoint, which includes username, public email, and full name. Also grants access to read-only API endpoints under /users. TokenScopeReadUser = TokenScope("read_user") // TokenScopeSudo grants permission to perform API actions as any user in the system, when authenticated as an administrator. TokenScopeSudo = TokenScope("sudo") // TokenScopeAdminMode grants permission to perform API actions as an administrator, when Admin Mode is enabled. TokenScopeAdminMode = TokenScope("admin_mode") // TokenScopeAiFeatures grants permission to perform API actions for GitLab Duo. This scope is designed to work with the GitLab Duo Plugin for JetBrains. For all other extensions, see scope requirements. TokenScopeAiFeatures = TokenScope("ai_features") // TokenScopeK8SProxy grants permission to perform Kubernetes API calls using the agent for Kubernetes. TokenScopeK8SProxy = TokenScope("k8s_proxy") // TokenScopeReadServicePing grant access to download Service Ping payload through the API when authenticated as an admin use. TokenScopeReadServicePing = TokenScope("read_service_ping") TokenScopeUnknown = TokenScope("") )
View Source
const ( TokenTypePersonal = TokenType("personal") TokenTypeProject = TokenType("project") TokenTypeGroup = TokenType("group") TokenTypeUserServiceAccount = TokenType("user-service-account") TokenTypeGroupServiceAccount = TokenType("group-service-account") TokenTypeUnknown = TokenType("") )
View Source
const (
PathConfigStorage = "config"
)
View Source
const (
PathTokenRoleStorage = "token"
)
View Source
const (
SecretAccessTokenType = "access_tokens"
)
Variables ¶
View Source
var ( ErrNilValue = errors.New("nil value") ErrInvalidValue = errors.New("invalid value") ErrFieldRequired = errors.New("required field") ErrFieldInvalidValue = errors.New("invalid value for field") ErrBackendNotConfigured = errors.New("backend not configured") )
View Source
var ( ErrAccessTokenNotFound = errors.New("access token not found") ErrRoleNotFound = errors.New("role not found") )
View Source
var ( ErrUnknownAccessLevel = errors.New("unknown access level") ValidAccessLevels = []string{ AccessLevelNoPermissions.String(), AccessLevelMinimalAccessPermissions.String(), AccessLevelGuestPermissions.String(), AccessLevelReporterPermissions.String(), AccessLevelDeveloperPermissions.String(), AccessLevelMaintainerPermissions.String(), AccessLevelOwnerPermissions.String(), } ValidPersonalAccessLevels = []string{ AccessLevelUnknown.String(), } ValidUserServiceAccountAccessLevels = []string{ AccessLevelUnknown.String(), } ValidGroupServiceAccountAccessLevels = []string{ AccessLevelUnknown.String(), } ValidProjectAccessLevels = []string{ AccessLevelGuestPermissions.String(), AccessLevelReporterPermissions.String(), AccessLevelDeveloperPermissions.String(), AccessLevelMaintainerPermissions.String(), AccessLevelOwnerPermissions.String(), } ValidGroupAccessLevels = []string{ AccessLevelGuestPermissions.String(), AccessLevelReporterPermissions.String(), AccessLevelDeveloperPermissions.String(), AccessLevelMaintainerPermissions.String(), AccessLevelOwnerPermissions.String(), } )
View Source
var ( ErrUnknownTokenScope = errors.New("unknown token scope") ValidGroupTokenScopes = validTokenScopes ValidProjectTokenScopes = validTokenScopes ValidPersonalTokenScopes = []string{ TokenScopeReadServicePing.String(), TokenScopeReadUser.String(), TokenScopeSudo.String(), TokenScopeAdminMode.String(), } ValidUserServiceAccountTokenScopes = []string{ TokenScopeReadServicePing.String(), TokenScopeReadUser.String(), TokenScopeSudo.String(), TokenScopeAdminMode.String(), } ValidGroupServiceAccountTokenScopes = []string{ TokenScopeReadServicePing.String(), TokenScopeReadUser.String(), TokenScopeSudo.String(), TokenScopeAdminMode.String(), } )
View Source
var BuildDate string
View Source
var (
ErrUnknownTokenType = errors.New("unknown token type")
)
View Source
var (
ErrUnknownType = errors.New("unknown gitlab type")
)
View Source
var ( FieldSchemaConfig = map[string]*framework.FieldSchema{ "token": { Type: framework.TypeString, Description: "The API access token required for authenticating requests to the GitLab API. This token must be a valid personal access token or any other type of token supported by GitLab for API access.", Required: true, DisplayAttrs: &framework.DisplayAttributes{ Name: "Token", Sensitive: true, }, }, "base_url": { Type: framework.TypeString, Required: true, DisplayAttrs: &framework.DisplayAttributes{ Name: "GitLab Base URL", }, Description: `The base URL of your GitLab instance. This could be the URL of a self-hosted GitLab instance or the URL of the GitLab SaaS service (https://gitlab.com). The URL must be properly formatted, including the scheme (http or https). This field is essential as it determines the endpoint where API requests will be directed.`, }, "type": { Type: framework.TypeString, Required: true, AllowedValues: []any{ TypeSelfManaged, TypeSaaS, TypeDedicated, }, Description: `The type of GitLab instance you are connecting to. This could typically distinguish between 'self-hosted' for on-premises GitLab installations or 'saas' or 'dedicated' for the GitLab SaaS offering. This field helps the plugin to adjust any necessary configurations or request patterns specific to the type of GitLab instance.`, DisplayAttrs: &framework.DisplayAttributes{ Name: "GitLab Type", }, }, "auto_rotate_token": { Type: framework.TypeBool, Default: false, Description: `Determines whether the plugin should automatically rotate the API access token as it approaches its expiration date. Enabling this feature ensures that the token is refreshed without manual intervention, reducing the risk of service disruption due to expired tokens.`, DisplayAttrs: &framework.DisplayAttributes{ Name: "Auto Rotate Token", }, }, "auto_rotate_before": { Type: framework.TypeDurationSecond, Description: `Specifies the duration, in seconds, before the token's expiration at which the auto-rotation should occur. The value must be set between a minimum of 24 hours (86400 seconds) and a maximum of 730 hours (2628000 seconds). This setting allows you to control how early the token rotation should happen, balancing between proactive rotation and maximizing token lifespan.`, Default: DefaultConfigFieldAccessTokenRotate, DisplayAttrs: &framework.DisplayAttributes{ Name: "Auto Rotate Before", }, }, "config_name": { Type: framework.TypeString, Description: "Config name", Required: true, DisplayAttrs: &framework.DisplayAttributes{ Name: "Config name", }, }, } )
View Source
var ( FieldSchemaRoles = map[string]*framework.FieldSchema{ "role_name": { Type: framework.TypeString, Description: "Role name", Required: true, DisplayAttrs: &framework.DisplayAttributes{ Name: "Role Name", }, }, "path": { Type: framework.TypeString, Description: "Project/Group path to create an access token for. If the token type is set to personal then write the username here.", Required: true, DisplayAttrs: &framework.DisplayAttributes{ Name: "path", }, }, "name": { Type: framework.TypeString, Description: "The name of the access token", Required: true, DisplayAttrs: &framework.DisplayAttributes{ Name: "Name", }, }, "scopes": { Type: framework.TypeCommaStringSlice, Description: "List of scopes", Required: false, DisplayAttrs: &framework.DisplayAttributes{ Name: "Scopes", }, AllowedValues: allowedValues(append(validTokenScopes, ValidPersonalTokenScopes...)...), }, "ttl": { Type: framework.TypeDurationSecond, Description: "The TTL of the token", Required: true, DisplayAttrs: &framework.DisplayAttributes{ Name: "Token TTL", }, }, "access_level": { Type: framework.TypeString, Description: "access level of access token (only required for Group and Project access tokens)", Required: false, DisplayAttrs: &framework.DisplayAttributes{ Name: "Access Level", }, AllowedValues: allowedValues(ValidAccessLevels...), }, "token_type": { Type: framework.TypeString, Description: "access token type", Required: true, AllowedValues: allowedValues(validTokenTypes...), DisplayAttrs: &framework.DisplayAttributes{ Name: "Token Type", }, }, "gitlab_revokes_token": { Type: framework.TypeBool, Default: false, Required: false, Description: `Gitlab revokes the token when it's time. Vault will not revoke the token when the lease expires.`, DisplayAttrs: &framework.DisplayAttributes{ Name: "Gitlab revokes token.", }, }, "config_name": { Type: framework.TypeString, Default: TypeConfigDefault, Required: false, Description: "The config we use when interacting with the role, this can be specified if you want to use a specific config for the role, otherwise it uses the default one.", DisplayAttrs: &framework.DisplayAttributes{ Name: "Configuration.", }, }, } )
View Source
var ( FieldSchemaTokenRole = map[string]*framework.FieldSchema{ "role_name": { Type: framework.TypeString, Description: "Role name", Required: true, }, } )
View Source
var FullCommit string
View Source
var Version string = "v0.0.0-dev"
Functions ¶
func GitlabClientNewContext ¶ added in v0.4.0
func HttpClientFromContext ¶ added in v0.4.0
func HttpClientNewContext ¶ added in v0.4.0
Types ¶
type AccessLevel ¶
type AccessLevel string
func AccessLevelParse ¶
func AccessLevelParse(value string) (AccessLevel, error)
func (AccessLevel) String ¶
func (i AccessLevel) String() string
func (AccessLevel) Value ¶
func (i AccessLevel) Value() int
type Backend ¶
func (*Backend) Invalidate ¶
Invalidate invalidates the key if required
type Client ¶
type Client interface { GitlabClient(ctx context.Context) *g.Client Valid(ctx context.Context) bool CurrentTokenInfo(ctx context.Context) (*EntryToken, error) RotateCurrentToken(ctx context.Context) (newToken *EntryToken, oldToken *EntryToken, err error) CreatePersonalAccessToken(ctx context.Context, username string, userId int, name string, expiresAt time.Time, scopes []string) (*EntryToken, error) CreateGroupAccessToken(ctx context.Context, groupId string, name string, expiresAt time.Time, scopes []string, accessLevel AccessLevel) (*EntryToken, error) CreateProjectAccessToken(ctx context.Context, projectId string, name string, expiresAt time.Time, scopes []string, accessLevel AccessLevel) (*EntryToken, error) RevokePersonalAccessToken(ctx context.Context, tokenId int) error RevokeProjectAccessToken(ctx context.Context, tokenId int, projectId string) error RevokeGroupAccessToken(ctx context.Context, tokenId int, groupId string) error GetUserIdByUsername(ctx context.Context, username string) (int, error) GetGroupIdByPath(ctx context.Context, path string) (int, error) CreateGroupServiceAccountAccessToken(ctx context.Context, group string, groupId string, userId int, name string, expiresAt time.Time, scopes []string) (*EntryToken, error) CreateUserServiceAccountAccessToken(ctx context.Context, username string, userId int, name string, expiresAt time.Time, scopes []string) (*EntryToken, error) RevokeUserServiceAccountAccessToken(ctx context.Context, token string) error RevokeGroupServiceAccountAccessToken(ctx context.Context, token string) error }
func GitlabClientFromContext ¶ added in v0.4.0
func NewGitlabClient ¶
func NewGitlabClient(config *EntryConfig, httpClient *http.Client, logger hclog.Logger) (client Client, err error)
type EntryConfig ¶ added in v0.2.0
type EntryConfig struct { TokenId int `json:"token_id" yaml:"token_id" mapstructure:"token_id"` BaseURL string `json:"base_url" structs:"base_url" mapstructure:"base_url"` Token string `json:"token" structs:"token" mapstructure:"token"` AutoRotateToken bool `json:"auto_rotate_token" structs:"auto_rotate_token" mapstructure:"auto_rotate_token"` AutoRotateBefore time.Duration `json:"auto_rotate_before" structs:"auto_rotate_before" mapstructure:"auto_rotate_before"` TokenCreatedAt time.Time `json:"token_created_at" structs:"token_created_at" mapstructure:"token_created_at"` TokenExpiresAt time.Time `json:"token_expires_at" structs:"token_expires_at" mapstructure:"token_expires_at"` Scopes []string `json:"scopes" structs:"scopes" mapstructure:"scopes"` Type Type `json:"type" structs:"type" mapstructure:"type"` Name string `json:"name" structs:"name" mapstructure:"name"` }
func (*EntryConfig) LogicalResponseData ¶ added in v0.2.0
func (e *EntryConfig) LogicalResponseData() map[string]any
func (*EntryConfig) UpdateFromFieldData ¶ added in v0.5.0
func (e *EntryConfig) UpdateFromFieldData(data *framework.FieldData) (warnings []string, err error)
type EntryRole ¶ added in v0.5.0
type EntryRole struct { RoleName string `json:"role_name" structs:"role_name" mapstructure:"role_name"` TTL time.Duration `json:"ttl" structs:"ttl" mapstructure:"ttl"` Path string `json:"path" structs:"path" mapstructure:"path"` Name string `json:"name" structs:"name" mapstructure:"name"` Scopes []string `json:"scopes" structs:"scopes" mapstructure:"scopes"` AccessLevel AccessLevel `json:"access_level" structs:"access_level" mapstructure:"access_level,omitempty"` TokenType TokenType `json:"token_type" structs:"token_type" mapstructure:"token_type"` GitlabRevokesTokens bool `json:"gitlab_revokes_token" structs:"gitlab_revokes_token" mapstructure:"gitlab_revokes_token"` ConfigName string `json:"config_name" structs:"config_name" mapstructure:"config_name"` }
func (EntryRole) LogicalResponseData ¶ added in v0.5.0
type EntryToken ¶
type EntryToken struct { TokenID int `json:"token_id"` UserID int `json:"user_id"` ParentID string `json:"parent_id"` Path string `json:"path"` Name string `json:"name"` Token string `json:"token"` TokenType TokenType `json:"token_type"` CreatedAt *time.Time `json:"created_at"` ExpiresAt *time.Time `json:"expires_at"` Scopes []string `json:"scopes"` AccessLevel AccessLevel `json:"access_level"` // not used for personal access tokens RoleName string `json:"role_name"` ConfigName string `json:"config_name"` GitlabRevokesToken bool `json:"gitlab_revokes_token"` }
func (EntryToken) SecretResponse ¶
func (e EntryToken) SecretResponse() (map[string]any, map[string]any)
type TokenScope ¶
type TokenScope string
func TokenScopeParse ¶
func TokenScopeParse(value string) (TokenScope, error)
func (TokenScope) String ¶
func (i TokenScope) String() string
func (TokenScope) Value ¶
func (i TokenScope) Value() string
Source Files ¶
- backend.go
- defs.go
- entry_config.go
- entry_role.go
- entry_token.go
- events.go
- gitlab_client.go
- gitlab_type.go
- name_tpl.go
- path_config.go
- path_config_list.go
- path_config_rotate.go
- path_role.go
- path_token_role.go
- secret_access_tokens.go
- type_access_level.go
- type_token_scope.go
- type_token_type.go
- utils.go
- version.go
Click to show internal directories.
Click to hide internal directories.