Documentation
¶
Index ¶
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 (
PathConfigFlags = "flags"
)
View Source
const (
PathConfigStorage = "config"
)
View Source
const (
PathTokenRoleStorage = "token"
)
View Source
const (
SecretAccessTokenType = "access_tokens"
)
Variables ¶
View Source
var ( ErrAccessTokenNotFound = errors.New("access token not found") ErrRoleNotFound = errors.New("role not found") )
View Source
var BuildDate string
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-managed 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{ gitlab.TypeSelfManaged, gitlab.TypeSaaS, gitlab.TypeDedicated, }, Description: `The type of GitLab instance you are connecting to. This could typically distinguish between 'self-managed' 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 FieldSchemaFlags = map[string]*framework.FieldSchema{ "show_config_token": { Type: framework.TypeBool, Description: "Should we display the token value for the roles?", Default: false, DisplayAttrs: &framework.DisplayAttributes{Name: "Show Config Token"}, }, }
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: utils.ToAny(token.ValidPersonalTokenScopes...), }, "ttl": { Type: framework.TypeDurationSecond, Description: "The TTL of the token", Required: false, 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: utils.ToAny(token.ValidAccessLevels...), }, "token_type": { Type: framework.TypeString, Description: "access token type", Required: true, AllowedValues: utils.ToAny(token.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 ¶
Types ¶
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
Metadata(ctx context.Context) (*g.Metadata, error)
CurrentTokenInfo(ctx context.Context) (*models.TokenConfig, error)
RotateCurrentToken(ctx context.Context) (newToken *models.TokenConfig, oldToken *models.TokenConfig, err error)
CreatePersonalAccessToken(ctx context.Context, username string, userId int, name string, expiresAt time.Time, scopes []string) (*models.TokenPersonal, error)
CreateGroupAccessToken(ctx context.Context, groupId string, name string, expiresAt time.Time, scopes []string, accessLevel t.AccessLevel) (*models.TokenGroup, error)
CreateProjectAccessToken(ctx context.Context, projectId string, name string, expiresAt time.Time, scopes []string, accessLevel t.AccessLevel) (*models.TokenProject, 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)
GetProjectIdByPath(ctx context.Context, path string) (int, error)
CreateGroupServiceAccountAccessToken(ctx context.Context, group string, groupId string, userId int, name string, expiresAt time.Time, scopes []string) (*models.TokenGroupServiceAccount, error)
CreateUserServiceAccountAccessToken(ctx context.Context, username string, userId int, name string, expiresAt time.Time, scopes []string) (*models.TokenUserServiceAccount, error)
RevokeUserServiceAccountAccessToken(ctx context.Context, token string) error
RevokeGroupServiceAccountAccessToken(ctx context.Context, token string) error
CreatePipelineProjectTriggerAccessToken(ctx context.Context, path, name string, projectId int, description string, expiresAt *time.Time) (*models.TokenPipelineProjectTrigger, error)
RevokePipelineProjectTriggerAccessToken(ctx context.Context, projectId int, tokenId int) error
CreateProjectDeployToken(ctx context.Context, path string, projectId int, name string, expiresAt *time.Time, scopes []string) (et *models.TokenProjectDeploy, err error)
RevokeProjectDeployToken(ctx context.Context, projectId, deployTokenId int) (err error)
CreateGroupDeployToken(ctx context.Context, path string, groupId int, name string, expiresAt *time.Time, scopes []string) (et *models.TokenGroupDeploy, err error)
RevokeGroupDeployToken(ctx context.Context, groupId, deployTokenId int) (err error)
}
func NewGitlabClient ¶
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 gitlab.Type `json:"type" structs:"type" mapstructure:"type"`
Name string `json:"name" structs:"name" mapstructure:"name"`
GitlabVersion string `json:"gitlab_version" structs:"gitlab_version" mapstructure:"gitlab_version"`
GitlabRevision string `json:"gitlab_revision" structs:"gitlab_revision" mapstructure:"gitlab_revision"`
GitlabIsEnterprise bool `json:"gitlab_is_enterprise" structs:"gitlab_is_enterprise" mapstructure:"gitlab_is_enterprise"`
}
func (*EntryConfig) LogicalResponseData ¶ added in v0.2.0
func (e *EntryConfig) LogicalResponseData(includeToken bool) (data 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 token.AccessLevel `json:"access_level" structs:"access_level" mapstructure:"access_level,omitempty"`
TokenType token.Type `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
Source Files
¶
Click to show internal directories.
Click to hide internal directories.