Skip to content

[KeyManager] Introduce Key Management Agent#749

Open
NilanjanDaw wants to merge 6 commits intogoogle:mainfrom
NilanjanDaw:add-kma-launcher
Open

[KeyManager] Introduce Key Management Agent#749
NilanjanDaw wants to merge 6 commits intogoogle:mainfrom
NilanjanDaw:add-kma-launcher

Conversation

@NilanjanDaw
Copy link
Copy Markdown
Collaborator

@NilanjanDaw NilanjanDaw commented Apr 20, 2026

This commit introduces the foundational infrastructure for the Key Management Agent (KMA), enabling the KeyManager to run as a standalone service independent of the main launcher. It establishes the architectural groundwork for the KEY_PROTECTION_VM security milestone by supporting distinct service roles (WSD and KPS) and multiple key protection mechanisms within a unified entrypoint.

Key Changes
- Unified Agent Launcher: Introduced keymanager/cmd/agent, a standalone entrypoint that replaces the previous WSD-only command. It supports both WSD (Workload Service Daemon) and KPS (Key Protection Service) roles via the SERVICE_ROLE environment variable.
- Multi-Mode Support: Implemented logic to switch between KEY_PROTECTION_VM_EMULATED and KEY_PROTECTION_VM modes, ensuring full backward compatibility while preparing for isolated VM deployments.
- Containerization: Introduces the KMA Dockerfile to build and deploy the unified /kma binary
- Testing Infrastructure:
- Added unit and integration tests for the agent lifecycle, including graceful shutdown and socket management.
- Introduced a Cloud Build configuration to automatically validate the containerized agent and its REST APIs via the UDS interface.

This PR is dependent on #743

@NilanjanDaw NilanjanDaw changed the title [KeyManager] Introduce independent Key Management Agent with KEY_PROTECTION_VM support [KeyManager] Introduce Key Management Agent Apr 20, 2026
…ECTION_VM support

This commit introduces the foundational infrastructure for the Key
Management Agent (KMA), enabling the KeyManager to run as a standalone
service independent of the main launcher. It establishes the
architectural groundwork for the KEY_PROTECTION_VM security milestone by
supporting distinct service roles (WSD and KPS) and multiple key
protection mechanisms within a unified entrypoint.

Key Changes
    - Unified Agent Launcher: Introduced keymanager/cmd/agent, a
    standalone entrypoint that replaces the previous WSD-only command.
    It supports both WSD (Workload Service Daemon) and KPS
    (Key Protection Service) roles via the SERVICE_ROLE environment
    variable.
    - Multi-Mode Support: Implemented logic to switch between
    KEY_PROTECTION_VM_EMULATED and KEY_PROTECTION_VM modes, ensuring
    full backward compatibility while preparing for isolated VM
    deployments.
    - Containerization: Introduces the KMA Dockerfile to build and deploy
    the unified /kma binary
    - Testing Infrastructure:
        - Added unit and integration tests for the agent lifecycle,
        including graceful shutdown and socket management.
        - Introduced a Cloud Build configuration to automatically
        validate the containerized agent and its REST APIs via the UDS
        interface.
Comment thread keymanager/cmd/agent/main_test.go Outdated

errChan := make(chan error, 1)
go func() {
errChan <- runWSD(ctx, socketPath)
Copy link
Copy Markdown
Contributor

@meetrajvala meetrajvala Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will also have to pass KPS mechanism here and in the following tests where we call runWSD.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack fixed.

Comment thread keymanager/cmd/agent/main_test.go Outdated

errChan := make(chan error, 1)
go func() {
errChan <- runWSD(ctx, socketPath)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the number of expected args here is 3. need to pass mode

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, fixed.

Comment thread keymanager/cmd/agent/main.go Outdated
Comment on lines +29 to +35
modeStr := os.Getenv("KEY_PROTECTION_MECHANISM")
mode := keymanager.KeyProtectionMechanism_KEY_PROTECTION_VM_EMULATED
if modeStr != "" {
if v, ok := keymanager.KeyProtectionMechanism_value[modeStr]; ok {
mode = keymanager.KeyProtectionMechanism(v)
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even though we control the pipeline, what if someone sets an incorrect env like "RANDOM_MODE", our code won't fail in such case right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, add a separate environment variable parser to handle these.

Comment thread keymanager/cmd/agent/main.go Outdated
Comment on lines +37 to +43
roleStr := os.Getenv("SERVICE_ROLE")
role := keymanager.ServiceRole_WSD
if roleStr != "" {
if v, ok := keymanager.ServiceRole_value[roleStr]; ok {
role = keymanager.ServiceRole(v)
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. our code won't fail if value of env SERVICE_ROLE isn't recognized.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, add a separate environment variable parser to handle these.

RUN cargo install bindgen-cli

WORKDIR /app
COPY . .
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add .dockerignore to avoid copying all the files like .git?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack added a .gitignore file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants