Documentation
¶
Overview ¶
Package onepassword provides an OmniVault provider for 1Password.
This package implements the vault.Vault interface using the official 1Password Go SDK, allowing applications to access secrets stored in 1Password vaults through the unified OmniVault interface.
Authentication requires a 1Password Service Account token. Create one at: https://my.1password.com/developer-tools/infrastructure-secrets/serviceaccount/
Basic usage:
provider, err := onepassword.New(onepassword.Config{
ServiceAccountToken: os.Getenv("OP_SERVICE_ACCOUNT_TOKEN"),
})
if err != nil {
log.Fatal(err)
}
defer provider.Close()
secret, err := provider.Get(ctx, "Private/API Keys/github-token")
With OmniVault resolver:
resolver := omnivault.NewResolver()
resolver.Register("op", provider)
value, err := resolver.Resolve(ctx, "op://Private/API Keys/github-token")
Index ¶
- Constants
- Variables
- type Config
- type ParsedPath
- type Provider
- func (p *Provider) Capabilities() vault.Capabilities
- func (p *Provider) Close() error
- func (p *Provider) Delete(ctx context.Context, path string) error
- func (p *Provider) DeleteBatch(ctx context.Context, paths []string) error
- func (p *Provider) Exists(ctx context.Context, path string) (bool, error)
- func (p *Provider) Get(ctx context.Context, path string) (*vault.Secret, error)
- func (p *Provider) GetBatch(ctx context.Context, paths []string) (map[string]*vault.Secret, error)
- func (p *Provider) List(ctx context.Context, prefix string) ([]string, error)
- func (p *Provider) Name() string
- func (p *Provider) Set(ctx context.Context, path string, secret *vault.Secret) error
- func (p *Provider) SetBatch(ctx context.Context, secrets map[string]*vault.Secret) error
Constants ¶
const ( // ProviderName is the name returned by Provider.Name(). ProviderName = "onepassword" // EnvServiceAccountToken is the environment variable for the service account token. EnvServiceAccountToken = "OP_SERVICE_ACCOUNT_TOKEN" //nolint:gosec // G101: this is an env var name, not a credential // DefaultIntegrationName identifies this integration to 1Password. DefaultIntegrationName = "omnivault-onepassword" // DefaultIntegrationVersion is the default version string. DefaultIntegrationVersion = "0.1.0" )
const ( CategoryLogin = op.ItemCategoryLogin CategorySecureNote = op.ItemCategorySecureNote CategoryAPICredentials = op.ItemCategoryAPICredentials CategoryDatabase = op.ItemCategoryDatabase CategoryServer = op.ItemCategoryServer CategoryPassword = op.ItemCategoryPassword CategorySSHKey = op.ItemCategorySSHKey )
Common item categories re-exported for convenience.
Variables ¶
var ErrInvalidPath = errors.New("invalid path format")
ErrInvalidPath is returned when a path cannot be parsed.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// ServiceAccountToken is the 1Password service account token.
// Required. Can also be set via OP_SERVICE_ACCOUNT_TOKEN environment variable.
ServiceAccountToken string
// IntegrationName identifies this integration to 1Password.
// Default: "omnivault-onepassword"
IntegrationName string
// IntegrationVersion is the version of this integration.
// Default: "0.1.0"
IntegrationVersion string
// DefaultVaultID is used when path doesn't specify a vault.
// Takes precedence over DefaultVaultName if both are set.
DefaultVaultID string
// DefaultVaultName is used when path doesn't specify a vault.
// Resolved to ID on first use.
DefaultVaultName string
// DefaultCategory is the item category for newly created items.
// Default: CategorySecureNote
DefaultCategory op.ItemCategory
// CacheTTL enables caching of vault/item ID lookups.
// Zero disables caching. Default: 0 (disabled)
CacheTTL time.Duration
// Logger for debug output. Optional.
Logger *slog.Logger
}
Config holds configuration for the 1Password provider.
type ParsedPath ¶
type ParsedPath struct {
// Vault is the vault name or ID.
Vault string
// Item is the item name or ID.
Item string
// Section is the section name (optional).
Section string
// Field is the field name (optional).
Field string
}
ParsedPath represents a parsed 1Password secret path.
func ParsePath ¶
func ParsePath(path string, defaultVault string) (*ParsedPath, error)
ParsePath parses a path string into components.
Supported formats:
- "vault/item/field" - full path with vault, item, and field
- "vault/item" - vault and item (returns all fields)
- "item/field" - item and field (uses defaultVault)
- "item" - item only (uses defaultVault, returns all fields)
- "vault/item/section/field" - full path with section
- "op://vault/item/field" - native 1Password secret reference
func (*ParsedPath) SecretReference ¶
func (p *ParsedPath) SecretReference() string
SecretReference returns the path as a 1Password secret reference URI.
func (*ParsedPath) String ¶
func (p *ParsedPath) String() string
String returns the path in canonical format.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements vault.Vault for 1Password.
func NewFromEnv ¶
NewFromEnv creates a new provider using the OP_SERVICE_ACCOUNT_TOKEN environment variable.
func NewWithContext ¶
NewWithContext creates a new 1Password provider with context.
func (*Provider) Capabilities ¶
func (p *Provider) Capabilities() vault.Capabilities
Capabilities returns the provider capabilities.
func (*Provider) DeleteBatch ¶
DeleteBatch removes multiple secrets in a single operation. Note: 1Password SDK doesn't support batch deletes, so this is implemented as sequential operations.
func (*Provider) Get ¶
Get retrieves a secret from 1Password.
Path formats supported:
- "vault/item/field" - returns the specific field value
- "vault/item" - returns the item with all fields
- "item/field" - uses default vault (if configured)
- "op://vault/item/field" - native 1Password secret reference
func (*Provider) GetBatch ¶
GetBatch retrieves multiple secrets in a single operation. This implements the vault.BatchVault interface.
Note: The 1Password SDK v0.1.x doesn't support batch resolution, so this is implemented as sequential Resolve calls.