Below is a Mermaid diagram that illustrates the process of issuing and verifying a token with HashiCorp Vault. This process involves a client requesting a token from Vault (issuing) and then using that token to access a secured resource (verifying).
Mermaid is a markdown-inspired script language for generating charts from text via a JavaScript integration. It's fantastic for documentation and can be used in Markdown files, GitHub README files, and various wiki platforms that support the Mermaid plugin or integration.
Here's the diagram:
mermaid
sequenceDiagram
participant Client as "Client Application"
participant Vault as "HashiCorp Vault"
participant Resource as "Secured Resource"
Note over Client,Vault: Token Issuance (Authentication)
Client->>Vault: 1. Auth Request (e.g., username/password, LDAP, etc.)
Vault->>Vault: 2. Authenticate Credentials
Vault->>Vault: 3. Generate Token (with policies attached)
Vault->>Client: 4. Return Token (e.g., `s.3qJ9pRx...`)
Note over Client: Client receives and stores the token securely
Note over Client,Resource: Accessing Secured Resource (Token Verification)
Client->>Resource: 5. Request Access (with token: `s.3qJ9pRx...`)
Resource->>Vault: 6. Verify Token (lookup by token ID `s.3qJ9pRx...`)
Vault->>Vault: 7. Validate Token<br/>- Check token integrity<br/>- Check token expiration<br/>- Evaluate attached policies
Vault->>Resource: 8. Return Token Status (valid/invalid, associated policies)
alt Token is Valid
Resource->>Resource: 9. Authorize Access (based on policies)
Resource->>Client: 10. Grant Access to Resource
else Token is Invalid
Resource->>Client: 10. Deny Access (401 Unauthorized)
end
Note over Client,Resource: Process Complete
Let's walk through what's happening in this sequence diagram:
Token Issuance (Authentication):
The Client initiates an authentication request to Vault with credentials (like username/password, an API key, LDAP auth, etc.).
Vault authenticates these credentials against the configured auth method.
Upon successful authentication, Vault generates a Token associated with the client, embedding policies that define what the client can access.
Vault returns this token back to the Client.
Accessing Secured Resource (Token Verification):
With the token in hand, the Client makes a request to access a Secured Resource, passing the token as proof of identity (commonly in an Authorization header as Bearer <token>).
The Secured Resource (which trusts Vault for authentication/authorization) contacts Vault to Verify the Token.
Vault checks the token's:
Integrity: Ensures the token wasn't tampered with.
Expiration: Verifies the token hasn't expired.
Policies: Evaluates what the token holder is allowed to do/access based on attached policies.
Vault informs the Secured Resource whether the token is valid and what permissions (policies) the token grants.
If the Token is Valid, the Resource grants access to the client based on the token's associated policies.
If the Token is Invalid (expired, revoked, malformed, etc.), the Resource denies access, typically responding with a 401 Unauthorized status.
This flow encapsulates the core concepts:
Authentication (Who are you?) happens between the client and Vault, resulting in a token.
Authorization (What can you do?) is enforced by Vault's policies attached to the token and evaluated by the secured resource upon each access request, with Vault acting as the trusted authority.
You can copy and paste this code into any platform supporting Mermaid (like GitHub Markdown files, Bitbucket Wiki, Markdown editors with Mermaid plugin, etc.) to visualize the sequence diagram. Happy documenting!