Environment Locking

This feature requires sfp-pro with sfp-server

Environment locking prevents concurrent access to shared environments. When a pipeline or developer locks an environment, others must wait until the lock is released, ensuring deployments don't conflict.

Why Lock Environments?

Without locking, multiple operations can interfere with each other:

┌─────────────────────────────────────────────────────────────────┐
│                    Without Locking (Problem)                    │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Pipeline A ────────> Deploy v1.0 ─────────┐                   │
│                                             │                   │
│   Pipeline B ────────> Deploy v1.1 ────┐    │                   │
│                                        ▼    ▼                   │
│                                   ┌──────────────┐              │
│                                   │     UAT      │ Conflict!    │
│                                   │   (broken)   │              │
│                                   └──────────────┘              │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│                    With Locking (Solution)                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Pipeline A ── Lock ──> Deploy v1.0 ── Unlock ─┐               │
│                                                 │               │
│   Pipeline B ── Wait... ─────────────── Lock ───┼──> Deploy v1.1│
│                                                 ▼               │
│                                           ┌──────────────┐      │
│                                           │     UAT      │      │
│                                           │  (working)   │      │
│                                           └──────────────┘      │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

How Locking Works

Lock Request Flow

  1. Request Lock: Pipeline requests a lock, gets a ticket ID

  2. Queue Position: If environment is locked, request is queued

  3. Acquire Lock: When available, pipeline acquires the lock

  4. Perform Operations: Deploy, test, etc.

  5. Release Lock: Unlock when finished

Lock Properties

Property
Description

ticketId

Unique identifier for the lock request

lockedBy

Who holds the lock (user or application)

lockReason

Why the lock was acquired

expiresAt

When the lock expires

leaseDuration

How long the lock is valid

Requesting a Lock

Basic Lock Request

Output:

With Extended Duration

Acquiring the Lock

Once your request reaches the front of the queue:

This command:

  1. Waits for the lock to be available (polls every 30 seconds)

  2. Acquires the lock when available

  3. Retrieves credentials

  4. Authenticates locally

Wait for Lock (Automatic)

The --lock-ticket-id flag automatically waits for lock acquisition:

Releasing a Lock

Manual Release

Automatic Expiration

Locks automatically expire after the lease duration. This prevents orphaned locks from blocking deployments indefinitely.

CI/CD Integration

GitHub Actions with Locking

Handling Lock Timeouts

Lock Queue Management

View Queue Status

Output:

Cancel a Lock Request

Lock Credentials Security

When you acquire a lock, credentials are only revealed at that point:

This ensures credentials are only provided to the lock holder.

Troubleshooting

Lock Not Releasing

Check if the lock holder is still active:

If the lock is orphaned (holder crashed), wait for expiration or contact an admin.

Stuck in Queue

  • Check queue position

  • Verify your ticket ID is correct

  • Check if you have permission to lock

"Lock already held"

You already hold a lock on this environment:

Credentials Not Returned

Ensure you're using --lock-ticket-id when fetching:

Last updated