Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fcb720736b | |||
| c38fe412f8 | |||
| 3a920ce90c | |||
| c4d74c5682 |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "note-1768964774362-3y9dna8sm",
|
||||
"title": "working",
|
||||
"content": "\u25CF Done. Updated all vault locale files with the new translation keys.\n\n Summary of what\u0027s now in gitcaddy-vault:\n 1. Templates: list.tmpl, view.tmpl, audit.tmpl, tokens.tmpl (copied)\n 2. Locale files: Added 20\u002B new translation keys to all locale files\n\n What stays in gitcaddy-server:\n - Router handlers (routers/web/repo/vault/vault.go) - these call the vault service\n - Service interface definitions (services/vault/vault.go)\n - Locale files also need the keys (for ctx.Locale.Tr calls in templates)\n\n\u0060\u0060\u0060\n Now you need to:\n 1. Commit and tag vault as v1.0.32\n 2. Update server go.mod to v1.0.32\n 3. Release server v3.1.10\n 4. Deploy to git-test\n\u0060\u0060\u0060",
|
||||
"content": "● Done. Updated all vault locale files with the new translation keys.\n\n Summary of what's now in gitcaddy-vault:\n 1. Templates: list.tmpl, view.tmpl, audit.tmpl, tokens.tmpl (copied)\n 2. Locale files: Added 20+ new translation keys to all locale files\n\n What stays in gitcaddy-server:\n - Router handlers (routers/web/repo/vault/vault.go) - these call the vault service\n - Service interface definitions (services/vault/vault.go)\n - Locale files also need the keys (for ctx.Locale.Tr calls in templates)\n\n```\n Now you need to:\n 1. Commit and tag vault as v1.0.32\n 2. Update server go.mod to v1.0.32\n 3. Release server v3.1.10\n 4. Deploy to git-test\n```\n\n● So:\n\n | Key | Value |\n |---------------------------|------------------------------------------------------------------|\n | Old (SECRET_KEY fallback) | bfe6e73282adba6545c2c9ba3542a332a80d62d1644b3b24c14b020a838c136f |\n | New (MASTER_KEY) | af1a7e9d7fe73258800b434ab5ffe7bf1ee3dff49740ef3cc3c5c014587acc08 |\n",
|
||||
"createdAt": 1768964774360,
|
||||
"updatedAt": 1768965391358
|
||||
"updatedAt": 1770432337981
|
||||
}
|
||||
77
README.md
77
README.md
@@ -336,6 +336,83 @@ Set `GITCADDY_DEV_MODE=1` to skip license validation during development:
|
||||
export GITCADDY_DEV_MODE=1
|
||||
```
|
||||
|
||||
## Key Management
|
||||
|
||||
### Master Key Configuration
|
||||
|
||||
The vault uses a master Key Encryption Key (KEK) to encrypt repository-level Data Encryption Keys (DEKs). Configure the master key using one of these methods (in priority order):
|
||||
|
||||
1. **app.ini** (recommended for production):
|
||||
```ini
|
||||
[vault]
|
||||
MASTER_KEY = <64-character-hex-string>
|
||||
```
|
||||
|
||||
2. **Environment variable**:
|
||||
```bash
|
||||
export GITCADDY_VAULT_KEY="<64-character-hex-string>"
|
||||
```
|
||||
|
||||
3. **Key file**:
|
||||
```bash
|
||||
export GITCADDY_VAULT_KEY_FILE="/etc/gitcaddy/vault.key"
|
||||
```
|
||||
|
||||
4. **Fallback** (not recommended): If none of the above are set, Gitea's `SECRET_KEY` is used as a fallback.
|
||||
|
||||
**Generate a secure master key:**
|
||||
```bash
|
||||
openssl rand -hex 32
|
||||
```
|
||||
|
||||
### Key Migration
|
||||
|
||||
If you change your master key or need to migrate from the fallback key to a dedicated master key, use the Key Migration feature.
|
||||
|
||||
**When to use key migration:**
|
||||
- You changed the `MASTER_KEY` in app.ini and existing secrets are now inaccessible
|
||||
- Secrets were created using the fallback key before a dedicated master key was configured
|
||||
- You see "Encryption Key Mismatch" errors when accessing vault secrets
|
||||
|
||||
**Web UI:**
|
||||
1. Navigate to Repository > Vault > Key Migration (admin only)
|
||||
2. Enter the old master key (the previous `MASTER_KEY` or Gitea's `SECRET_KEY`)
|
||||
3. Choose the migration scope (this repository or all repositories)
|
||||
4. Click "Start Migration"
|
||||
|
||||
**API:**
|
||||
```bash
|
||||
curl -X POST \
|
||||
-H "Authorization: Bearer $VAULT_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"old_key": "<previous-master-key-or-secret-key>",
|
||||
"repo_id": 0
|
||||
}' \
|
||||
https://gitcaddy.example.com/owner/repo/-/vault/api/migrate-key
|
||||
```
|
||||
|
||||
The `old_key` can be:
|
||||
- A 64-character hex string (will be decoded to 32 bytes)
|
||||
- Raw text (will be used as-is, padded/truncated to 32 bytes)
|
||||
|
||||
Set `repo_id` to `0` to migrate the current repository, or specify a repo ID for a specific repository. Instance admins can migrate all repositories at once.
|
||||
|
||||
### DEK Rotation (Enterprise)
|
||||
|
||||
For enhanced security, Enterprise license holders can rotate the Data Encryption Key (DEK) for a repository. This generates a new DEK and re-encrypts all secret versions.
|
||||
|
||||
**Web UI:**
|
||||
1. Navigate to Repository > Vault > Key Migration
|
||||
2. Click "Rotate DEK" in the DEK Rotation section
|
||||
|
||||
**API:**
|
||||
```bash
|
||||
curl -X POST \
|
||||
-H "Authorization: Bearer $VAULT_TOKEN" \
|
||||
https://gitcaddy.example.com/owner/repo/-/vault/api/rotate-key
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
1. **Key Management** - The master KEK should be stored securely (HSM, KMS, or secure environment variable)
|
||||
|
||||
@@ -187,6 +187,45 @@ func (m *Manager) KeySource() string {
|
||||
return m.keySource
|
||||
}
|
||||
|
||||
// SetKey sets the master key directly (used for migration with old keys).
|
||||
// The key must be exactly 32 bytes. If less, it will be padded. If more, it will be truncated.
|
||||
func (m *Manager) SetKey(key []byte) {
|
||||
if len(key) < 32 {
|
||||
padded := make([]byte, 32)
|
||||
copy(padded, key)
|
||||
key = padded
|
||||
} else if len(key) > 32 {
|
||||
key = key[:32]
|
||||
}
|
||||
m.masterKey = key
|
||||
m.keySource = "direct"
|
||||
}
|
||||
|
||||
// GetFallbackKey returns Gitea's SECRET_KEY as bytes for migration purposes.
|
||||
// This allows migrating secrets that were encrypted with the fallback key
|
||||
// to a dedicated MASTER_KEY.
|
||||
func GetFallbackKey() []byte {
|
||||
if setting.SecretKey == "" {
|
||||
return nil
|
||||
}
|
||||
key := []byte(setting.SecretKey)
|
||||
// Ensure key is 32 bytes
|
||||
if len(key) < 32 {
|
||||
padded := make([]byte, 32)
|
||||
copy(padded, key)
|
||||
key = padded
|
||||
} else if len(key) > 32 {
|
||||
key = key[:32]
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
// HasDedicatedMasterKey returns true if a dedicated MASTER_KEY is configured
|
||||
// (not using the fallback SECRET_KEY)
|
||||
func HasDedicatedMasterKey() bool {
|
||||
return defaultManager.HasMasterKey() && !defaultManager.IsUsingFallbackKey()
|
||||
}
|
||||
|
||||
// Encrypt encrypts plaintext using AES-256-GCM
|
||||
// Returns: nonce || ciphertext || tag
|
||||
func (m *Manager) Encrypt(plaintext []byte, key []byte) ([]byte, error) {
|
||||
|
||||
@@ -165,5 +165,46 @@
|
||||
"vault.key_mismatch_solution_1": "Restore the original MASTER_KEY that was used when secrets were created",
|
||||
"vault.key_mismatch_solution_2": "If using the fallback key previously, temporarily remove MASTER_KEY from [vault] section to use the original key",
|
||||
"vault.key_mismatch_solution_3": "Contact your administrator to migrate secrets to the new key",
|
||||
"vault.key_mismatch_admin_note": "Admin: Check app.ini [vault] MASTER_KEY setting and compare with the key used when secrets were originally created."
|
||||
"vault.key_mismatch_admin_note": "Admin: Check app.ini [vault] MASTER_KEY setting and compare with the key used when secrets were originally created.",
|
||||
"vault.key_migration_title": "Key Migration",
|
||||
"vault.key_migration_description": "Migrate vault secrets from an old encryption key to the current key",
|
||||
"vault.key_migration_warning_title": "Important",
|
||||
"vault.key_migration_warning": "This operation will re-encrypt your vault's data encryption keys using the current master key. Make sure you have the correct old key before proceeding.",
|
||||
"vault.when_to_migrate": "When to use key migration",
|
||||
"vault.migrate_reason_1": "You changed the MASTER_KEY in app.ini and existing secrets are now inaccessible",
|
||||
"vault.migrate_reason_2": "Secrets were created using the fallback key (Gitea's SECRET_KEY) before a dedicated MASTER_KEY was configured",
|
||||
"vault.migrate_reason_3": "You're seeing 'Encryption Key Mismatch' errors when accessing vault secrets",
|
||||
"vault.old_master_key": "Old Master Key",
|
||||
"vault.old_key_placeholder": "Enter the previous encryption key",
|
||||
"vault.old_key_help": "Enter the old MASTER_KEY or Gitea's SECRET_KEY that was used when secrets were originally created. Can be hex-encoded (64 characters) or raw text.",
|
||||
"vault.migration_scope": "Migration Scope",
|
||||
"vault.migrate_this_repo": "This repository only",
|
||||
"vault.migrate_all_repos": "All repositories (instance-wide)",
|
||||
"vault.migration_scope_help": "Choose whether to migrate just this repository or all repositories with vault data",
|
||||
"vault.confirm_migrate": "Are you sure you want to migrate the encryption keys? This cannot be undone.",
|
||||
"vault.start_migration": "Start Migration",
|
||||
"vault.migration_complete": "Migration Complete",
|
||||
"vault.migration_success_count": "%d repository keys migrated successfully",
|
||||
"vault.migration_failed_count": "%d repository keys failed to migrate",
|
||||
"vault.migration_failed": "Migration Failed",
|
||||
"vault.dek_rotation_title": "DEK Rotation (Enterprise)",
|
||||
"vault.dek_rotation_description": "Generate a new Data Encryption Key and re-encrypt all secrets. This is a security best practice for periodic key rotation.",
|
||||
"vault.dek_rotation_enterprise_only": "DEK rotation requires an Enterprise license.",
|
||||
"vault.confirm_rotate": "Are you sure you want to rotate the encryption key? All secret versions will be re-encrypted.",
|
||||
"vault.rotate_dek": "Rotate DEK",
|
||||
"vault.key_management": "Key Management",
|
||||
"vault.old_key_required": "Old master key is required",
|
||||
"vault.dek_rotation_complete": "DEK rotation completed successfully",
|
||||
"vault.migrate_from_fallback": "Migrate from Fallback Key",
|
||||
"vault.migrate_from_fallback_description": "Your vault is using a dedicated MASTER_KEY, but existing secrets were encrypted with Gitea's SECRET_KEY (fallback). Click below to automatically migrate all secrets to your new master key.",
|
||||
"vault.migrate_from_fallback_button": "Migrate All Secrets to MASTER_KEY",
|
||||
"vault.no_dedicated_master_key": "No dedicated MASTER_KEY is configured. Cannot migrate from fallback.",
|
||||
"vault.no_fallback_key": "Could not retrieve the fallback key.",
|
||||
"vault.migration_from_fallback_success": "Successfully migrated %d repository keys to the new master key.",
|
||||
"vault.migration_partial_success": "Migration completed: %d succeeded, %d failed.",
|
||||
"vault.current_key_source": "Current key source",
|
||||
"vault.one_click_migration": "One-Click Migration",
|
||||
"vault.manual_migration": "Manual Migration",
|
||||
"vault.manual_migration_description": "If your secrets were encrypted with a different key (not the fallback), enter it manually below.",
|
||||
"vault.confirm_migrate_fallback": "This will migrate all vault secrets from the fallback key (Gitea SECRET_KEY) to your dedicated MASTER_KEY. This operation cannot be undone. Continue?"
|
||||
}
|
||||
@@ -136,6 +136,39 @@ func RotateVaultRepoKey(ctx context.Context, key *VaultRepoKey, userID int64, en
|
||||
return UpdateVaultRepoKey(ctx, key, "encrypted_dek", "previous_key_data", "key_version", "rotated_unix", "rotated_by")
|
||||
}
|
||||
|
||||
// MigrateVaultRepoKey migrates a repo's DEK from one master key to another.
|
||||
// This is used when the master KEK changes - the DEK itself stays the same,
|
||||
// but it gets re-encrypted with the new master key.
|
||||
// decryptWithOldKey decrypts the DEK using the old master key
|
||||
// encryptWithNewKey encrypts the DEK using the new (current) master key
|
||||
func MigrateVaultRepoKey(ctx context.Context, key *VaultRepoKey, decryptWithOldKey func([]byte) ([]byte, error), encryptWithNewKey func([]byte) ([]byte, error)) error {
|
||||
// Decrypt DEK with old master key
|
||||
dek, err := decryptWithOldKey(key.EncryptedDEK)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Re-encrypt DEK with new master key
|
||||
newEncryptedDEK, err := encryptWithNewKey(dek)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Store old encrypted DEK for potential recovery
|
||||
key.PreviousKeyData = key.EncryptedDEK
|
||||
key.EncryptedDEK = newEncryptedDEK
|
||||
key.KeyVersion++
|
||||
|
||||
return UpdateVaultRepoKey(ctx, key, "encrypted_dek", "previous_key_data", "key_version")
|
||||
}
|
||||
|
||||
// GetAllVaultRepoKeys returns all vault repo keys (for migration purposes)
|
||||
func GetAllVaultRepoKeys(ctx context.Context) ([]*VaultRepoKey, error) {
|
||||
var keys []*VaultRepoKey
|
||||
err := db.GetEngine(ctx).Find(&keys)
|
||||
return keys, err
|
||||
}
|
||||
|
||||
// DeleteVaultRepoKey deletes a vault key (use with caution - all secrets become unrecoverable)
|
||||
func DeleteVaultRepoKey(ctx context.Context, repoID int64) error {
|
||||
_, err := db.GetEngine(ctx).Where("repo_id = ?", repoID).Delete(&VaultRepoKey{})
|
||||
|
||||
@@ -37,6 +37,9 @@ type VaultSecret struct {
|
||||
CreatedBy int64 `xorm:"NOT NULL"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"updated NOT NULL"`
|
||||
|
||||
// Encryption mode: "standard" (server-side) or "lockbox" (client E2E encrypted)
|
||||
EncryptionMode string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'standard'"`
|
||||
|
||||
// Soft delete
|
||||
DeletedUnix timeutil.TimeStamp `xorm:"INDEX"` // 0 = active, >0 = soft deleted
|
||||
DeletedBy int64
|
||||
|
||||
501
routes/routes.go
501
routes/routes.go
@@ -31,14 +31,15 @@ var Version = "dev"
|
||||
|
||||
// Template names for vault pages
|
||||
const (
|
||||
tplVaultList templates.TplName = "repo/vault/list"
|
||||
tplVaultView templates.TplName = "repo/vault/view"
|
||||
tplVaultNew templates.TplName = "repo/vault/new"
|
||||
tplVaultVersions templates.TplName = "repo/vault/versions"
|
||||
tplVaultCompare templates.TplName = "repo/vault/compare"
|
||||
tplVaultAudit templates.TplName = "repo/vault/audit"
|
||||
tplVaultTokens templates.TplName = "repo/vault/tokens"
|
||||
tplVaultKeyError templates.TplName = "repo/vault/key_error"
|
||||
tplVaultList templates.TplName = "repo/vault/list"
|
||||
tplVaultView templates.TplName = "repo/vault/view"
|
||||
tplVaultNew templates.TplName = "repo/vault/new"
|
||||
tplVaultVersions templates.TplName = "repo/vault/versions"
|
||||
tplVaultCompare templates.TplName = "repo/vault/compare"
|
||||
tplVaultAudit templates.TplName = "repo/vault/audit"
|
||||
tplVaultTokens templates.TplName = "repo/vault/tokens"
|
||||
tplVaultKeyError templates.TplName = "repo/vault/key_error"
|
||||
tplVaultKeyMigrate templates.TplName = "repo/vault/key_migrate"
|
||||
)
|
||||
|
||||
// API Response types
|
||||
@@ -48,6 +49,7 @@ type SecretResponse struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Type string `json:"type"`
|
||||
EncryptionMode string `json:"encryption_mode,omitempty"` // "standard" or "lockbox"
|
||||
CurrentVersion int `json:"current_version"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
@@ -114,11 +116,12 @@ type TokenInfoResponse struct {
|
||||
|
||||
// CreateSecretRequest is the request body for creating a secret
|
||||
type CreateSecretRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
Value string `json:"value" binding:"required"`
|
||||
Comment string `json:"comment"` // Used when updating existing secret
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
Value string `json:"value" binding:"required"`
|
||||
Comment string `json:"comment"` // Used when updating existing secret
|
||||
EncryptionMode string `json:"encryption_mode"` // "standard" (default) or "lockbox"
|
||||
}
|
||||
|
||||
// UpdateSecretRequest is the request body for updating a secret
|
||||
@@ -151,6 +154,12 @@ func RegisterRepoWebRoutes(r plugins.PluginRouter, lic *license.Manager) {
|
||||
r.Post("/tokens", webCreateToken(lic))
|
||||
r.Post("/tokens/{id}/revoke", webRevokeToken(lic))
|
||||
|
||||
// Key management routes (admin only)
|
||||
r.Get("/migrate-key", webKeyMigratePage(lic))
|
||||
r.Post("/migrate-key", webMigrateKey(lic))
|
||||
r.Post("/migrate-from-fallback", webMigrateFromFallback(lic))
|
||||
r.Post("/rotate-key", webRotateKey(lic))
|
||||
|
||||
// Static secret routes first
|
||||
r.Get("/secrets/new", webNewSecretForm(lic))
|
||||
r.Post("/secrets/new", webCreateSecret(lic))
|
||||
@@ -199,6 +208,9 @@ func RegisterRepoAPIRoutes(r plugins.PluginRouter, lic *license.Manager) {
|
||||
|
||||
// Key rotation (enterprise)
|
||||
r.Post("/rotate-key", apiRotateKey(lic))
|
||||
|
||||
// Key migration (admin only - migrate from old master key to new)
|
||||
r.Post("/migrate-key", apiMigrateKey(lic))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -262,10 +274,15 @@ func requireRepoWrite(ctx *context.APIContext) bool {
|
||||
}
|
||||
|
||||
func secretToResponse(s *models.VaultSecret) SecretResponse {
|
||||
encMode := s.EncryptionMode
|
||||
if encMode == "" {
|
||||
encMode = "standard"
|
||||
}
|
||||
return SecretResponse{
|
||||
Name: s.Name,
|
||||
Description: s.Description,
|
||||
Type: string(s.Type),
|
||||
EncryptionMode: encMode,
|
||||
CurrentVersion: s.CurrentVersion,
|
||||
CreatedAt: int64(s.CreatedUnix),
|
||||
UpdatedAt: int64(s.UpdatedUnix),
|
||||
@@ -554,6 +571,28 @@ func apiPutSecret(lic *license.Manager) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// Validate encryption mode
|
||||
encryptionMode := req.EncryptionMode
|
||||
if encryptionMode == "" {
|
||||
encryptionMode = "standard"
|
||||
}
|
||||
if encryptionMode != "standard" && encryptionMode != "lockbox" {
|
||||
ctx.JSON(http.StatusBadRequest, map[string]any{
|
||||
"error": "invalid_encryption_mode",
|
||||
"message": "encryption_mode must be 'standard' or 'lockbox'",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Validate lockbox format: must start with "lockbox:v1:"
|
||||
if encryptionMode == "lockbox" && !strings.HasPrefix(req.Value, "lockbox:v1:") {
|
||||
ctx.JSON(http.StatusBadRequest, map[string]any{
|
||||
"error": "invalid_lockbox_format",
|
||||
"message": "Lockbox secrets must be pre-encrypted with format 'lockbox:v1:<salt>:<ciphertext>'",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Check if secret exists
|
||||
existing, err := services.GetSecret(ctx, ctx.Repo.Repository.ID, name)
|
||||
if err == services.ErrSecretNotFound {
|
||||
@@ -566,11 +605,12 @@ func apiPutSecret(lic *license.Manager) http.HandlerFunc {
|
||||
limits = &info.Limits
|
||||
}
|
||||
secret, err := services.CreateSecret(ctx, ctx.Repo.Repository.ID, services.CreateSecretOptions{
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
Type: req.Type,
|
||||
Value: req.Value,
|
||||
CreatorID: ctx.Doer.ID,
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
Type: req.Type,
|
||||
Value: req.Value,
|
||||
EncryptionMode: encryptionMode,
|
||||
CreatorID: ctx.Doer.ID,
|
||||
}, limits)
|
||||
if err != nil {
|
||||
switch err {
|
||||
@@ -1218,20 +1258,159 @@ func apiRotateKey(lic *license.Manager) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Implement key rotation
|
||||
// This involves:
|
||||
// 1. Generate new DEK
|
||||
// 2. Re-encrypt all secret versions with new DEK
|
||||
// 3. Update the repo key
|
||||
// This should be done in a transaction
|
||||
// Rotate the DEK for this repository
|
||||
err := services.RotateRepoKey(ctx, services.RotateRepoKeyOptions{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
IPAddress: ctx.RemoteAddr(),
|
||||
})
|
||||
|
||||
ctx.JSON(http.StatusNotImplemented, map[string]any{
|
||||
"error": "not_implemented",
|
||||
"message": "Key rotation coming soon",
|
||||
if err != nil {
|
||||
if isKeyMismatchError(err) {
|
||||
ctx.JSON(http.StatusConflict, map[string]any{
|
||||
"error": "key_mismatch",
|
||||
"message": "Cannot rotate key: encryption key mismatch. The vault master key may have changed since secrets were created. Use /migrate-key first.",
|
||||
})
|
||||
return
|
||||
}
|
||||
log.Error("Failed to rotate key for repo %d: %v", ctx.Repo.Repository.ID, err)
|
||||
ctx.JSON(http.StatusInternalServerError, map[string]any{
|
||||
"error": "rotation_failed",
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"message": "DEK rotation completed successfully",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// MigrateKeyRequest is the request body for key migration
|
||||
type MigrateKeyRequest struct {
|
||||
OldKey string `json:"old_key"` // The old master key (hex-encoded or raw)
|
||||
RepoID int64 `json:"repo_id"` // Optional: specific repo to migrate (0 = all repos)
|
||||
}
|
||||
|
||||
func apiMigrateKey(lic *license.Manager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !requireWebLicense(lic, r) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := getRepoContext(r)
|
||||
if ctx == nil || ctx.Repo == nil || ctx.Repo.Repository == nil {
|
||||
http.Error(w, "Repository context not found", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Must be repo admin
|
||||
if !requireRepoAdmin(ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
var req MigrateKeyRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
ctx.JSON(http.StatusBadRequest, map[string]any{
|
||||
"error": "invalid_request",
|
||||
"message": "Invalid JSON body",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if req.OldKey == "" {
|
||||
ctx.JSON(http.StatusBadRequest, map[string]any{
|
||||
"error": "missing_old_key",
|
||||
"message": "old_key is required",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Parse the old key (try hex first, then raw)
|
||||
var oldKeyBytes []byte
|
||||
if len(req.OldKey) == 64 {
|
||||
// Try hex decode
|
||||
decoded, err := hexDecode(req.OldKey)
|
||||
if err == nil {
|
||||
oldKeyBytes = decoded
|
||||
}
|
||||
}
|
||||
if oldKeyBytes == nil {
|
||||
// Use as raw bytes
|
||||
oldKeyBytes = []byte(req.OldKey)
|
||||
}
|
||||
|
||||
// Ensure key is 32 bytes
|
||||
if len(oldKeyBytes) < 32 {
|
||||
padded := make([]byte, 32)
|
||||
copy(padded, oldKeyBytes)
|
||||
oldKeyBytes = padded
|
||||
} else if len(oldKeyBytes) > 32 {
|
||||
oldKeyBytes = oldKeyBytes[:32]
|
||||
}
|
||||
|
||||
// If repo_id not specified, use current repo
|
||||
repoID := req.RepoID
|
||||
if repoID == 0 {
|
||||
repoID = ctx.Repo.Repository.ID
|
||||
}
|
||||
|
||||
results, err := services.MigrateRepoKeys(ctx, services.MigrateRepoKeyOptions{
|
||||
OldKey: oldKeyBytes,
|
||||
RepoID: repoID,
|
||||
UserID: ctx.Doer.ID,
|
||||
IPAddress: ctx.RemoteAddr(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Error("Failed to migrate keys: %v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, map[string]any{
|
||||
"error": "migration_failed",
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Check results
|
||||
successCount := 0
|
||||
failedCount := 0
|
||||
var failedRepos []map[string]any
|
||||
for _, result := range results {
|
||||
if result.Success {
|
||||
successCount++
|
||||
} else {
|
||||
failedCount++
|
||||
failedRepos = append(failedRepos, map[string]any{
|
||||
"repo_id": result.RepoID,
|
||||
"error": result.Error,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"message": "Key migration completed",
|
||||
"success_count": successCount,
|
||||
"failed_count": failedCount,
|
||||
"failed_repos": failedRepos,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// hexDecode decodes a hex string to bytes
|
||||
func hexDecode(s string) ([]byte, error) {
|
||||
result := make([]byte, len(s)/2)
|
||||
for i := 0; i < len(s); i += 2 {
|
||||
var b byte
|
||||
_, err := fmt.Sscanf(s[i:i+2], "%02x", &b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result[i/2] = b
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Web Handlers (HTML rendering)
|
||||
// ============================================================================
|
||||
@@ -2054,3 +2233,271 @@ func webRevokeToken(lic *license.Manager) http.HandlerFunc {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault/tokens")
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Key Management Web Handlers
|
||||
// ============================================================================
|
||||
|
||||
func webKeyMigratePage(lic *license.Manager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !requireWebLicense(lic, r) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := getWebContext(r)
|
||||
if ctx == nil || ctx.Repo == nil || ctx.Repo.Repository == nil {
|
||||
http.Error(w, "Context not found", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Must be repo admin
|
||||
if !ctx.Repo.IsAdmin() {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Title"] = ctx.Tr("vault.key_migration_title")
|
||||
ctx.Data["PageIsVault"] = true
|
||||
ctx.Data["IsRepoAdmin"] = ctx.Repo.IsAdmin()
|
||||
|
||||
// Check if user is instance admin (can migrate all repos)
|
||||
ctx.Data["IsInstanceAdmin"] = ctx.Doer != nil && ctx.Doer.IsAdmin
|
||||
|
||||
// Check license tier for DEK rotation
|
||||
info := lic.Info()
|
||||
ctx.Data["IsEnterprise"] = info != nil && info.Tier == "enterprise"
|
||||
|
||||
// Check if a dedicated MASTER_KEY is configured (not using fallback)
|
||||
// If so, show the one-click migration from fallback option
|
||||
ctx.Data["HasDedicatedMasterKey"] = crypto.HasDedicatedMasterKey()
|
||||
ctx.Data["KeySource"] = crypto.KeySource()
|
||||
|
||||
ctx.HTML(http.StatusOK, tplVaultKeyMigrate)
|
||||
}
|
||||
}
|
||||
|
||||
func webMigrateKey(lic *license.Manager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !requireWebLicense(lic, r) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := getWebContext(r)
|
||||
if ctx == nil || ctx.Repo == nil || ctx.Repo.Repository == nil {
|
||||
http.Error(w, "Context not found", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Must be repo admin
|
||||
if !ctx.Repo.IsAdmin() {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
oldKeyStr := r.FormValue("old_key")
|
||||
scope := r.FormValue("scope")
|
||||
|
||||
if oldKeyStr == "" {
|
||||
ctx.Flash.Error(ctx.Tr("vault.old_key_required"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault/migrate-key")
|
||||
return
|
||||
}
|
||||
|
||||
// Parse the old key (try hex first, then raw)
|
||||
var oldKeyBytes []byte
|
||||
if len(oldKeyStr) == 64 {
|
||||
decoded, err := hexDecode(oldKeyStr)
|
||||
if err == nil {
|
||||
oldKeyBytes = decoded
|
||||
}
|
||||
}
|
||||
if oldKeyBytes == nil {
|
||||
oldKeyBytes = []byte(oldKeyStr)
|
||||
}
|
||||
|
||||
// Ensure key is 32 bytes
|
||||
if len(oldKeyBytes) < 32 {
|
||||
padded := make([]byte, 32)
|
||||
copy(padded, oldKeyBytes)
|
||||
oldKeyBytes = padded
|
||||
} else if len(oldKeyBytes) > 32 {
|
||||
oldKeyBytes = oldKeyBytes[:32]
|
||||
}
|
||||
|
||||
// Determine scope
|
||||
var repoID int64
|
||||
if scope == "all" && ctx.Doer != nil && ctx.Doer.IsAdmin {
|
||||
repoID = 0 // Migrate all repos
|
||||
} else {
|
||||
repoID = ctx.Repo.Repository.ID // Just this repo
|
||||
}
|
||||
|
||||
results, err := services.MigrateRepoKeys(ctx, services.MigrateRepoKeyOptions{
|
||||
OldKey: oldKeyBytes,
|
||||
RepoID: repoID,
|
||||
UserID: ctx.Doer.ID,
|
||||
IPAddress: ctx.RemoteAddr(),
|
||||
})
|
||||
|
||||
ctx.Data["Title"] = ctx.Tr("vault.key_migration_title")
|
||||
ctx.Data["PageIsVault"] = true
|
||||
ctx.Data["IsRepoAdmin"] = ctx.Repo.IsAdmin()
|
||||
ctx.Data["IsInstanceAdmin"] = ctx.Doer != nil && ctx.Doer.IsAdmin
|
||||
|
||||
info := lic.Info()
|
||||
ctx.Data["IsEnterprise"] = info != nil && info.Tier == "enterprise"
|
||||
|
||||
if err != nil {
|
||||
ctx.Data["MigrationError"] = err.Error()
|
||||
ctx.HTML(http.StatusOK, tplVaultKeyMigrate)
|
||||
return
|
||||
}
|
||||
|
||||
// Build result summary
|
||||
successCount := 0
|
||||
failedCount := 0
|
||||
var failedRepos []map[string]any
|
||||
for _, result := range results {
|
||||
if result.Success {
|
||||
successCount++
|
||||
} else {
|
||||
failedCount++
|
||||
failedRepos = append(failedRepos, map[string]any{
|
||||
"RepoID": result.RepoID,
|
||||
"Error": result.Error,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["MigrationResult"] = map[string]any{
|
||||
"SuccessCount": successCount,
|
||||
"FailedCount": failedCount,
|
||||
"FailedRepos": failedRepos,
|
||||
}
|
||||
|
||||
ctx.HTML(http.StatusOK, tplVaultKeyMigrate)
|
||||
}
|
||||
}
|
||||
|
||||
func webMigrateFromFallback(lic *license.Manager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !requireWebLicense(lic, r) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := getWebContext(r)
|
||||
if ctx == nil || ctx.Repo == nil || ctx.Repo.Repository == nil {
|
||||
http.Error(w, "Context not found", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Must be repo admin
|
||||
if !ctx.Repo.IsAdmin() {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Must have a dedicated MASTER_KEY configured
|
||||
if !crypto.HasDedicatedMasterKey() {
|
||||
ctx.Flash.Error(ctx.Tr("vault.no_dedicated_master_key"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault/migrate-key")
|
||||
return
|
||||
}
|
||||
|
||||
// Get the fallback key (Gitea's SECRET_KEY)
|
||||
fallbackKey := crypto.GetFallbackKey()
|
||||
if fallbackKey == nil {
|
||||
ctx.Flash.Error(ctx.Tr("vault.no_fallback_key"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault/migrate-key")
|
||||
return
|
||||
}
|
||||
|
||||
// Determine scope
|
||||
scope := r.FormValue("scope")
|
||||
var repoID int64
|
||||
if scope == "all" && ctx.Doer != nil && ctx.Doer.IsAdmin {
|
||||
repoID = 0 // Migrate all repos
|
||||
} else {
|
||||
repoID = ctx.Repo.Repository.ID // Just this repo
|
||||
}
|
||||
|
||||
results, err := services.MigrateRepoKeys(ctx, services.MigrateRepoKeyOptions{
|
||||
OldKey: fallbackKey,
|
||||
RepoID: repoID,
|
||||
UserID: ctx.Doer.ID,
|
||||
IPAddress: ctx.RemoteAddr(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault/migrate-key")
|
||||
return
|
||||
}
|
||||
|
||||
// Count results
|
||||
successCount := 0
|
||||
failedCount := 0
|
||||
for _, result := range results {
|
||||
if result.Success {
|
||||
successCount++
|
||||
} else {
|
||||
failedCount++
|
||||
}
|
||||
}
|
||||
|
||||
if failedCount == 0 {
|
||||
ctx.Flash.Success(ctx.Tr("vault.migration_from_fallback_success", successCount))
|
||||
} else {
|
||||
ctx.Flash.Warning(ctx.Tr("vault.migration_partial_success", successCount, failedCount))
|
||||
}
|
||||
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault")
|
||||
}
|
||||
}
|
||||
|
||||
func webRotateKey(lic *license.Manager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !requireWebLicense(lic, r) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := getWebContext(r)
|
||||
if ctx == nil || ctx.Repo == nil || ctx.Repo.Repository == nil {
|
||||
http.Error(w, "Context not found", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Must be repo admin
|
||||
if !ctx.Repo.IsAdmin() {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Check enterprise license
|
||||
info := lic.Info()
|
||||
if info == nil || info.Tier != "enterprise" {
|
||||
ctx.Flash.Error(ctx.Tr("vault.dek_rotation_enterprise_only"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault/migrate-key")
|
||||
return
|
||||
}
|
||||
|
||||
err := services.RotateRepoKey(ctx, services.RotateRepoKeyOptions{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
IPAddress: ctx.RemoteAddr(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if isKeyMismatchError(err) {
|
||||
ctx.Flash.Error(ctx.Tr("vault.key_mismatch_message"))
|
||||
} else {
|
||||
ctx.Flash.Error(err.Error())
|
||||
}
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault/migrate-key")
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("vault.dek_rotation_complete"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/vault")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,11 +106,12 @@ func GetSecretValue(ctx context.Context, repoID int64, name string, version int)
|
||||
|
||||
// CreateSecretOptions contains options for creating a secret
|
||||
type CreateSecretOptions struct {
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
Value string
|
||||
CreatorID int64
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
Value string
|
||||
EncryptionMode string // "standard" (default) or "lockbox"
|
||||
CreatorID int64
|
||||
}
|
||||
|
||||
// CreateSecret creates a new secret
|
||||
@@ -158,12 +159,19 @@ func CreateSecret(ctx context.Context, repoID int64, opts CreateSecretOptions, l
|
||||
|
||||
now := timeutil.TimeStampNow()
|
||||
|
||||
// Determine encryption mode
|
||||
encryptionMode := opts.EncryptionMode
|
||||
if encryptionMode == "" {
|
||||
encryptionMode = "standard"
|
||||
}
|
||||
|
||||
// Create the secret
|
||||
secret := &models.VaultSecret{
|
||||
RepoID: repoID,
|
||||
Name: opts.Name,
|
||||
Description: opts.Description,
|
||||
Type: models.SecretType(opts.Type),
|
||||
EncryptionMode: encryptionMode,
|
||||
CurrentVersion: 1,
|
||||
CreatedUnix: now,
|
||||
UpdatedUnix: now,
|
||||
@@ -460,3 +468,168 @@ func GetOrCreateRepoKey(ctx context.Context, repoID int64) (*models.VaultRepoKey
|
||||
|
||||
return key, nil
|
||||
}
|
||||
|
||||
// MigrateRepoKeyOptions contains options for migrating a repo's key
|
||||
type MigrateRepoKeyOptions struct {
|
||||
OldKey []byte // The old master key (raw 32 bytes)
|
||||
RepoID int64 // Specific repo to migrate (0 = all repos)
|
||||
UserID int64
|
||||
IPAddress string
|
||||
}
|
||||
|
||||
// MigrateRepoKeyResult contains the result of a key migration
|
||||
type MigrateRepoKeyResult struct {
|
||||
RepoID int64
|
||||
Success bool
|
||||
Error string
|
||||
}
|
||||
|
||||
// MigrateRepoKeys migrates repo DEKs from an old master key to the current master key.
|
||||
// This is used when the master KEK changes - the DEKs themselves stay the same,
|
||||
// but they get re-encrypted with the new master key.
|
||||
func MigrateRepoKeys(ctx context.Context, opts MigrateRepoKeyOptions) ([]MigrateRepoKeyResult, error) {
|
||||
var keys []*models.VaultRepoKey
|
||||
var err error
|
||||
|
||||
if opts.RepoID > 0 {
|
||||
key := &models.VaultRepoKey{RepoID: opts.RepoID}
|
||||
has, err := db.GetEngine(ctx).Get(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !has {
|
||||
return nil, ErrSecretNotFound
|
||||
}
|
||||
keys = []*models.VaultRepoKey{key}
|
||||
} else {
|
||||
keys, err = models.GetAllVaultRepoKeys(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
results := make([]MigrateRepoKeyResult, 0, len(keys))
|
||||
|
||||
// Create a temporary crypto manager with the old key
|
||||
oldManager := crypto.NewManager()
|
||||
oldManager.SetKey(opts.OldKey)
|
||||
|
||||
for _, key := range keys {
|
||||
result := MigrateRepoKeyResult{RepoID: key.RepoID}
|
||||
|
||||
err := models.MigrateVaultRepoKey(ctx, key,
|
||||
func(encrypted []byte) ([]byte, error) {
|
||||
// Decrypt with old key
|
||||
return oldManager.DecryptWithMasterKey(encrypted)
|
||||
},
|
||||
func(plaintext []byte) ([]byte, error) {
|
||||
// Encrypt with current (new) key
|
||||
return crypto.EncryptDEK(plaintext)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
result.Success = false
|
||||
result.Error = err.Error()
|
||||
} else {
|
||||
result.Success = true
|
||||
|
||||
// Log the migration
|
||||
_ = CreateAuditEntry(ctx, &models.VaultAuditEntry{
|
||||
RepoID: key.RepoID,
|
||||
Action: models.AuditActionRotateKey,
|
||||
UserID: opts.UserID,
|
||||
IPAddress: opts.IPAddress,
|
||||
Success: true,
|
||||
})
|
||||
}
|
||||
|
||||
results = append(results, result)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// RotateRepoKeyOptions contains options for rotating a repo's DEK
|
||||
type RotateRepoKeyOptions struct {
|
||||
RepoID int64
|
||||
UserID int64
|
||||
IPAddress string
|
||||
}
|
||||
|
||||
// RotateRepoKey rotates the DEK for a repository.
|
||||
// This generates a new DEK and re-encrypts all secret versions.
|
||||
func RotateRepoKey(ctx context.Context, opts RotateRepoKeyOptions) error {
|
||||
// Get the repo key
|
||||
key := &models.VaultRepoKey{RepoID: opts.RepoID}
|
||||
has, err := db.GetEngine(ctx).Get(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !has {
|
||||
return ErrSecretNotFound
|
||||
}
|
||||
|
||||
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||
err := models.RotateVaultRepoKey(ctx, key, opts.UserID,
|
||||
// encryptDEK - encrypt with current master key
|
||||
func(dek []byte) ([]byte, error) {
|
||||
return crypto.EncryptDEK(dek)
|
||||
},
|
||||
// reEncryptSecrets - re-encrypt all secret versions
|
||||
func(oldDEK, newDEK []byte) error {
|
||||
// Get all secrets for this repo
|
||||
var secrets []*models.VaultSecret
|
||||
if err := db.GetEngine(ctx).Where("repo_id = ?", opts.RepoID).Find(&secrets); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, secret := range secrets {
|
||||
// Get all versions
|
||||
var versions []*models.VaultSecretVersion
|
||||
if err := db.GetEngine(ctx).Where("secret_id = ?", secret.ID).Find(&versions); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, version := range versions {
|
||||
// Decrypt with old DEK
|
||||
plaintext, err := crypto.DecryptSecret(version.EncryptedValue, oldDEK)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to decrypt version %d of secret %s: %w", version.Version, secret.Name, err)
|
||||
}
|
||||
|
||||
// Encrypt with new DEK
|
||||
newEncrypted, err := crypto.EncryptSecret(plaintext, newDEK)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encrypt version %d of secret %s: %w", version.Version, secret.Name, err)
|
||||
}
|
||||
|
||||
// Update the version
|
||||
version.EncryptedValue = newEncrypted
|
||||
if _, err := db.GetEngine(ctx).ID(version.ID).Cols("encrypted_value").Update(version); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
// decryptDEK - decrypt with current master key
|
||||
func(encrypted []byte) ([]byte, error) {
|
||||
return crypto.DecryptDEK(encrypted)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Log the rotation
|
||||
return CreateAuditEntry(ctx, &models.VaultAuditEntry{
|
||||
RepoID: opts.RepoID,
|
||||
Action: models.AuditActionRotateKey,
|
||||
UserID: opts.UserID,
|
||||
IPAddress: opts.IPAddress,
|
||||
Success: true,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
{{if .IsRepoAdmin}}
|
||||
<div class="ui divider"></div>
|
||||
<p class="ui small text grey">{{ctx.Locale.Tr "vault.key_mismatch_admin_note"}}</p>
|
||||
<a class="ui primary button" href="{{.RepoLink}}/vault/migrate-key">
|
||||
{{svg "octicon-sync" 16}} {{ctx.Locale.Tr "vault.key_migration_title"}}
|
||||
</a>
|
||||
{{end}}
|
||||
</div>
|
||||
{{template "repo/vault/layout_footer" .}}
|
||||
|
||||
173
templates/repo/vault/key_migrate.tmpl
Normal file
173
templates/repo/vault/key_migrate.tmpl
Normal file
@@ -0,0 +1,173 @@
|
||||
{{template "repo/vault/layout_head" (dict "ctxData" . "pageClass" "repository vault key-migrate")}}
|
||||
<div class="ui segment">
|
||||
<h4 class="ui header">
|
||||
{{svg "octicon-key" 20}} {{ctx.Locale.Tr "vault.key_migration_title"}}
|
||||
<div class="sub header">{{ctx.Locale.Tr "vault.key_migration_description"}}</div>
|
||||
</h4>
|
||||
{{if .KeySource}}
|
||||
<div class="ui label">
|
||||
{{ctx.Locale.Tr "vault.current_key_source"}}: <strong>{{.KeySource}}</strong>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{if .MigrationResult}}
|
||||
<div class="ui {{if eq .MigrationResult.FailedCount 0}}positive{{else}}warning{{end}} message">
|
||||
<div class="header">{{ctx.Locale.Tr "vault.migration_complete"}}</div>
|
||||
<p>
|
||||
{{ctx.Locale.Tr "vault.migration_success_count" .MigrationResult.SuccessCount}}
|
||||
{{if gt .MigrationResult.FailedCount 0}}
|
||||
<br>{{ctx.Locale.Tr "vault.migration_failed_count" .MigrationResult.FailedCount}}
|
||||
{{end}}
|
||||
</p>
|
||||
{{if .MigrationResult.FailedRepos}}
|
||||
<ul class="ui list">
|
||||
{{range .MigrationResult.FailedRepos}}
|
||||
<li>Repo ID {{.RepoID}}: {{.Error}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .MigrationError}}
|
||||
<div class="ui negative message">
|
||||
<div class="header">{{ctx.Locale.Tr "vault.migration_failed"}}</div>
|
||||
<p>{{.MigrationError}}</p>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .HasDedicatedMasterKey}}
|
||||
<div class="ui segment">
|
||||
<h5 class="ui header">
|
||||
{{svg "octicon-zap" 16}} {{ctx.Locale.Tr "vault.one_click_migration"}}
|
||||
</h5>
|
||||
<div class="ui info message">
|
||||
<p>{{ctx.Locale.Tr "vault.migrate_from_fallback_description"}}</p>
|
||||
</div>
|
||||
<form class="ui form ignore-dirty" id="migrate-fallback-form" action="{{.RepoLink}}/vault/migrate-from-fallback" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="field">
|
||||
<select name="scope" class="ui dropdown">
|
||||
<option value="repo">{{ctx.Locale.Tr "vault.migrate_this_repo"}}</option>
|
||||
{{if .IsInstanceAdmin}}
|
||||
<option value="all" selected>{{ctx.Locale.Tr "vault.migrate_all_repos"}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<button class="ui primary button show-modal" data-modal="#migrate-fallback-modal" type="button">
|
||||
{{svg "octicon-sync" 16}} {{ctx.Locale.Tr "vault.migrate_from_fallback_button"}}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="ui horizontal divider">{{ctx.Locale.Tr "or"}}</div>
|
||||
{{end}}
|
||||
|
||||
<div class="ui segment">
|
||||
<h5 class="ui header">
|
||||
{{svg "octicon-key" 16}} {{ctx.Locale.Tr "vault.manual_migration"}}
|
||||
</h5>
|
||||
{{if .HasDedicatedMasterKey}}
|
||||
<p class="text grey">{{ctx.Locale.Tr "vault.manual_migration_description"}}</p>
|
||||
{{else}}
|
||||
<div class="ui warning message">
|
||||
<div class="header">{{ctx.Locale.Tr "vault.key_migration_warning_title"}}</div>
|
||||
<p>{{ctx.Locale.Tr "vault.key_migration_warning"}}</p>
|
||||
</div>
|
||||
|
||||
<h5 class="ui header">{{ctx.Locale.Tr "vault.when_to_migrate"}}</h5>
|
||||
<ul class="ui list">
|
||||
<li>{{ctx.Locale.Tr "vault.migrate_reason_1"}}</li>
|
||||
<li>{{ctx.Locale.Tr "vault.migrate_reason_2"}}</li>
|
||||
<li>{{ctx.Locale.Tr "vault.migrate_reason_3"}}</li>
|
||||
</ul>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
{{end}}
|
||||
|
||||
<form class="ui form ignore-dirty" id="migrate-manual-form" action="{{.RepoLink}}/vault/migrate-key" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="required field">
|
||||
<label>{{ctx.Locale.Tr "vault.old_master_key"}}</label>
|
||||
<input type="password" name="old_key" placeholder="{{ctx.Locale.Tr "vault.old_key_placeholder"}}" required>
|
||||
<p class="help">{{ctx.Locale.Tr "vault.old_key_help"}}</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ctx.Locale.Tr "vault.migration_scope"}}</label>
|
||||
<select name="scope" class="ui dropdown">
|
||||
<option value="repo">{{ctx.Locale.Tr "vault.migrate_this_repo"}}</option>
|
||||
{{if .IsInstanceAdmin}}
|
||||
<option value="all">{{ctx.Locale.Tr "vault.migrate_all_repos"}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
<p class="help">{{ctx.Locale.Tr "vault.migration_scope_help"}}</p>
|
||||
</div>
|
||||
<button class="ui {{if .HasDedicatedMasterKey}}{{else}}primary {{end}}button show-modal" data-modal="#migrate-manual-modal" type="button">
|
||||
{{svg "octicon-sync" 16}} {{ctx.Locale.Tr "vault.start_migration"}}
|
||||
</button>
|
||||
<a class="ui button" href="{{.RepoLink}}/vault">
|
||||
{{ctx.Locale.Tr "cancel"}}
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{{if .IsRepoAdmin}}
|
||||
<div class="ui segment">
|
||||
<h5 class="ui header">
|
||||
{{svg "octicon-sync" 16}} {{ctx.Locale.Tr "vault.dek_rotation_title"}}
|
||||
</h5>
|
||||
<p>{{ctx.Locale.Tr "vault.dek_rotation_description"}}</p>
|
||||
{{if .IsEnterprise}}
|
||||
<form class="ui form ignore-dirty" id="rotate-dek-form" action="{{.RepoLink}}/vault/rotate-key" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<button class="ui button show-modal" data-modal="#rotate-dek-modal" type="button">
|
||||
{{svg "octicon-sync" 16}} {{ctx.Locale.Tr "vault.rotate_dek"}}
|
||||
</button>
|
||||
</form>
|
||||
{{else}}
|
||||
<div class="ui info message">
|
||||
{{ctx.Locale.Tr "vault.dek_rotation_enterprise_only"}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .HasDedicatedMasterKey}}
|
||||
<div class="ui small modal" id="migrate-fallback-modal">
|
||||
<div class="header">{{svg "octicon-sync"}} {{ctx.Locale.Tr "vault.migrate_from_fallback"}}</div>
|
||||
<div class="content">
|
||||
<p>{{ctx.Locale.Tr "vault.confirm_migrate_fallback"}}</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui cancel button">{{ctx.Locale.Tr "cancel"}}</button>
|
||||
<button class="ui primary button" onclick="document.getElementById('migrate-fallback-form').submit();">{{ctx.Locale.Tr "vault.start_migration"}}</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<div class="ui small modal" id="migrate-manual-modal">
|
||||
<div class="header">{{svg "octicon-key"}} {{ctx.Locale.Tr "vault.manual_migration"}}</div>
|
||||
<div class="content">
|
||||
<p>{{ctx.Locale.Tr "vault.confirm_migrate"}}</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui cancel button">{{ctx.Locale.Tr "cancel"}}</button>
|
||||
<button class="ui primary button" onclick="document.getElementById('migrate-manual-form').submit();">{{ctx.Locale.Tr "vault.start_migration"}}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if and .IsRepoAdmin .IsEnterprise}}
|
||||
<div class="ui small modal" id="rotate-dek-modal">
|
||||
<div class="header">{{svg "octicon-sync"}} {{ctx.Locale.Tr "vault.dek_rotation_title"}}</div>
|
||||
<div class="content">
|
||||
<p>{{ctx.Locale.Tr "vault.confirm_rotate"}}</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui cancel button">{{ctx.Locale.Tr "cancel"}}</button>
|
||||
<button class="ui primary button" onclick="document.getElementById('rotate-dek-form').submit();">{{ctx.Locale.Tr "vault.rotate_dek"}}</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{template "repo/vault/layout_footer" .}}
|
||||
@@ -65,8 +65,11 @@
|
||||
<tr{{if .IsDeleted}} class="negative"{{end}}>
|
||||
<td>
|
||||
<a href="{{$.RepoLink}}/vault/secrets/{{.Name}}">
|
||||
{{svg "octicon-key" 16}} <strong>{{.Name}}</strong>
|
||||
{{if eq .EncryptionMode "lockbox"}}{{svg "octicon-lock" 16}}{{else}}{{svg "octicon-key" 16}}{{end}} <strong>{{.Name}}</strong>
|
||||
</a>
|
||||
{{if eq .EncryptionMode "lockbox"}}
|
||||
<span class="ui tiny blue label" data-tooltip="End-to-end encrypted">{{svg "octicon-shield-lock" 10}} Lock-Box</span>
|
||||
{{end}}
|
||||
{{if .Description}}
|
||||
<br><small class="text grey">{{.Description}}</small>
|
||||
{{end}}
|
||||
|
||||
@@ -119,9 +119,9 @@
|
||||
<td>{{.UsedCount}}</td>
|
||||
<td class="right aligned">
|
||||
{{if not .IsRevoked}}
|
||||
<form class="ui inline" action="{{$.RepoLink}}/vault/tokens/{{.ID}}/revoke" method="post">
|
||||
<form class="ui inline" id="revoke-form-{{.ID}}" action="{{$.RepoLink}}/vault/tokens/{{.ID}}/revoke" method="post">
|
||||
{{$.CsrfTokenHtml}}
|
||||
<button class="ui tiny red button" type="submit" onclick="return confirm('{{ctx.Locale.Tr "vault.confirm_revoke_token"}}');">
|
||||
<button class="ui tiny red button show-modal" type="button" data-modal="#revoke-token-modal" data-token-id="{{.ID}}">
|
||||
{{svg "octicon-x" 14}} {{ctx.Locale.Tr "vault.revoke"}}
|
||||
</button>
|
||||
</form>
|
||||
@@ -142,6 +142,17 @@
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<div class="ui small modal" id="revoke-token-modal">
|
||||
<div class="header">{{svg "octicon-x"}} {{ctx.Locale.Tr "vault.revoke"}}</div>
|
||||
<div class="content">
|
||||
<p>{{ctx.Locale.Tr "vault.confirm_revoke_token"}}</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui cancel button">{{ctx.Locale.Tr "cancel"}}</button>
|
||||
<button class="ui red button" id="revoke-confirm">{{ctx.Locale.Tr "vault.revoke"}}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('new-token-btn')?.addEventListener('click', function() {
|
||||
document.getElementById('new-token-form').style.display = 'block';
|
||||
@@ -157,5 +168,20 @@ document.getElementById('copy-token')?.addEventListener('click', function() {
|
||||
const input = document.getElementById('new-token-value');
|
||||
navigator.clipboard.writeText(input.value);
|
||||
});
|
||||
|
||||
// Revoke token modal
|
||||
(function() {
|
||||
let currentTokenId = null;
|
||||
document.querySelectorAll('[data-modal="#revoke-token-modal"]').forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
currentTokenId = this.getAttribute('data-token-id');
|
||||
});
|
||||
});
|
||||
document.getElementById('revoke-confirm')?.addEventListener('click', function() {
|
||||
if (currentTokenId) {
|
||||
document.getElementById('revoke-form-' + currentTokenId).submit();
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{{template "repo/vault/layout_footer" .}}
|
||||
|
||||
@@ -52,10 +52,10 @@
|
||||
{{svg "octicon-diff" 14}} {{ctx.Locale.Tr "vault.compare"}}
|
||||
</a>
|
||||
{{if and $.CanWrite (ne .Version $.Secret.CurrentVersion)}}
|
||||
<form class="ui inline tw-inline" action="{{$.RepoLink}}/vault/secrets/{{$.Secret.Name}}/rollback" method="post">
|
||||
<form class="ui inline tw-inline" id="rollback-form-{{.Version}}" action="{{$.RepoLink}}/vault/secrets/{{$.Secret.Name}}/rollback" method="post">
|
||||
{{$.CsrfTokenHtml}}
|
||||
<input type="hidden" name="version" value="{{.Version}}">
|
||||
<button class="ui button" type="submit" onclick="return confirm('{{ctx.Locale.Tr "vault.confirm_rollback" .Version}}');">
|
||||
<button class="ui button show-modal" type="button" data-modal="#rollback-modal" data-version="{{.Version}}">
|
||||
{{svg "octicon-history" 14}} {{ctx.Locale.Tr "vault.rollback"}}
|
||||
</button>
|
||||
</form>
|
||||
@@ -75,4 +75,33 @@
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{if .CanWrite}}
|
||||
<div class="ui small modal" id="rollback-modal">
|
||||
<div class="header">{{svg "octicon-history"}} {{ctx.Locale.Tr "vault.rollback"}}</div>
|
||||
<div class="content">
|
||||
<p id="rollback-message"></p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui cancel button">{{ctx.Locale.Tr "cancel"}}</button>
|
||||
<button class="ui primary button" id="rollback-confirm">{{ctx.Locale.Tr "vault.rollback"}}</button>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
(function() {
|
||||
let currentVersion = null;
|
||||
document.querySelectorAll('[data-modal="#rollback-modal"]').forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
currentVersion = this.getAttribute('data-version');
|
||||
document.getElementById('rollback-message').textContent = '{{ctx.Locale.Tr "vault.confirm_rollback" 0}}'.replace('0', currentVersion);
|
||||
});
|
||||
});
|
||||
document.getElementById('rollback-confirm')?.addEventListener('click', function() {
|
||||
if (currentVersion) {
|
||||
document.getElementById('rollback-form-' + currentVersion).submit();
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{{end}}
|
||||
{{template "repo/vault/layout_footer" .}}
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
<div class="tw-flex tw-items-start tw-justify-between tw-gap-4">
|
||||
<div>
|
||||
<h4 class="ui header tw-mb-0">
|
||||
{{if eq .Secret.EncryptionMode "lockbox"}}
|
||||
{{svg "octicon-lock" 20}} {{.Secret.Name}}
|
||||
<span class="ui blue label" data-tooltip="End-to-end encrypted. Use CLI/SDK to decrypt.">{{svg "octicon-shield-lock" 12}} Lock-Box</span>
|
||||
{{else}}
|
||||
{{svg "octicon-key" 20}} {{.Secret.Name}}
|
||||
{{end}}
|
||||
{{if .Secret.IsDeleted}}
|
||||
<span class="ui red label">{{ctx.Locale.Tr "vault.deleted"}}</span>
|
||||
{{end}}
|
||||
@@ -50,7 +55,52 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if .CanWrite}}
|
||||
{{if eq .Secret.EncryptionMode "lockbox"}}
|
||||
<!-- Lockbox secret - show locked state -->
|
||||
<div class="ui segment tw-text-center">
|
||||
<div class="tw-py-8">
|
||||
{{svg "octicon-lock" 64 "tw-text-blue-500"}}
|
||||
<h3 class="ui header tw-mt-4">Lock-Box Protected</h3>
|
||||
<p class="tw-text-secondary tw-max-w-md tw-mx-auto">
|
||||
This secret is end-to-end encrypted. The server cannot decrypt it.
|
||||
Use the CLI or SDK with your passphrase to access the value.
|
||||
</p>
|
||||
<div class="ui divider"></div>
|
||||
<div class="ui secondary segment tw-text-left tw-max-w-lg tw-mx-auto">
|
||||
<p class="tw-font-semibold tw-mb-2">CLI Usage:</p>
|
||||
<code class="tw-block tw-p-2 tw-bg-gray-100 dark:tw-bg-gray-800 tw-rounded tw-font-mono tw-text-sm">
|
||||
vault-resolve get --lockbox {{.Secret.Name}}
|
||||
</code>
|
||||
<p class="tw-font-semibold tw-mb-2 tw-mt-4">Go SDK:</p>
|
||||
<code class="tw-block tw-p-2 tw-bg-gray-100 dark:tw-bg-gray-800 tw-rounded tw-font-mono tw-text-sm">
|
||||
value, err := client.GetLockbox(ctx, "{{.Secret.Name}}", passphrase)
|
||||
</code>
|
||||
</div>
|
||||
{{if .CanWrite}}
|
||||
<div class="tw-mt-4">
|
||||
{{if .Secret.IsDeleted}}
|
||||
<button class="ui green button" type="button" onclick="document.getElementById('restore-form').submit();">
|
||||
{{svg "octicon-history" 16}} {{ctx.Locale.Tr "vault.restore"}}
|
||||
</button>
|
||||
{{else}}
|
||||
<button class="ui red button show-modal" type="button" data-modal="#delete-secret-modal">
|
||||
{{svg "octicon-trash" 16}} {{ctx.Locale.Tr "vault.delete"}}
|
||||
</button>
|
||||
{{end}}
|
||||
</div>
|
||||
{{if .Secret.IsDeleted}}
|
||||
<form id="restore-form" class="tw-hidden" action="{{.RepoLink}}/vault/secrets/{{.Secret.Name}}/restore" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
</form>
|
||||
{{else}}
|
||||
<form id="delete-form" class="tw-hidden" action="{{.RepoLink}}/vault/secrets/{{.Secret.Name}}/delete" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
</form>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{else if .CanWrite}}
|
||||
<!-- Editor view for users who can write -->
|
||||
<div class="ui segment">
|
||||
<h5 class="ui header">{{ctx.Locale.Tr "vault.edit_secret"}}</h5>
|
||||
@@ -92,7 +142,7 @@
|
||||
{{svg "octicon-history" 16}} {{ctx.Locale.Tr "vault.restore"}}
|
||||
</button>
|
||||
{{else}}
|
||||
<button class="ui red button" type="button" onclick="if(confirm('{{ctx.Locale.Tr "vault.confirm_delete"}}')) document.getElementById('delete-form').submit();">
|
||||
<button class="ui red button show-modal" type="button" data-modal="#delete-secret-modal">
|
||||
{{svg "octicon-trash" 16}} {{ctx.Locale.Tr "vault.delete"}}
|
||||
</button>
|
||||
{{end}}
|
||||
@@ -125,8 +175,8 @@
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{{else}}
|
||||
<!-- Read-only view for users who cannot write -->
|
||||
{{else if ne .Secret.EncryptionMode "lockbox"}}
|
||||
<!-- Read-only view for users who cannot write (standard secrets only) -->
|
||||
<div class="ui segment">
|
||||
<div class="tw-flex tw-items-center tw-justify-between tw-mb-4">
|
||||
<h5 class="ui header tw-mb-0">{{ctx.Locale.Tr "vault.secret_value"}}</h5>
|
||||
@@ -238,4 +288,17 @@
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if not .Secret.IsDeleted}}
|
||||
<div class="ui small modal" id="delete-secret-modal">
|
||||
<div class="header">{{svg "octicon-trash"}} {{ctx.Locale.Tr "vault.delete_secret"}}</div>
|
||||
<div class="content">
|
||||
<p>{{ctx.Locale.Tr "vault.confirm_delete"}}</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui cancel button">{{ctx.Locale.Tr "cancel"}}</button>
|
||||
<button class="ui red button" onclick="document.getElementById('delete-form').submit();">{{ctx.Locale.Tr "vault.delete"}}</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{template "repo/vault/layout_footer" .}}
|
||||
|
||||
Reference in New Issue
Block a user