Skip to content

feat: reworked announce key flow and validation#158

Merged
NamanBalaji merged 2 commits into
mainfrom
feat/key-request-validator
Jun 12, 2026
Merged

feat: reworked announce key flow and validation#158
NamanBalaji merged 2 commits into
mainfrom
feat/key-request-validator

Conversation

@NamanBalaji

Copy link
Copy Markdown
Contributor

This PR introduces a better flow for key operations starting with announce key and adds a validation package

  • Announce key request is validated and if we are announcing on root or a root key then no job is created, otherwise a job is created
  • If key already exists and is in In progress or completed stage we just return the existing key otherwise it's treated as a retry operation
  • On the confirm side we check if we have the latest job ID if not we cancel the job because it's stale and don't modify the key entry
  • If we are confirming the latest job we revalidate because there can be changes in the state and if validation passes we conform the job otherwise we cancel it and mark the key as failed so it can be retried.

Notes:

  • On Agent side we don't need any validations as whatever the root sends is trusted. In future when we implement operations with higher prio like suspend a parent or ancestor or delete a parent etc we traverse down the subtree cancel all the in progress job for child keys and then perform our operation. So root acts as the orchestrator and agents just accept.
  • For now announce is only possible when the parent is a direct parent of the key that's being announced and parent needs to be active, this can be changed in the future.

@jithinkunjachan jithinkunjachan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work

@@ -123,4 +126,52 @@ func TestAnnounceKey(t *testing.T) {
assert.Equal(t, first.GetKey().GetId(), second.GetKey().GetId())
assert.Equal(t, first.GetKey().GetKeyProcessingState().GetJobId(), second.GetKey().GetKeyProcessingState().GetJobId())
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shall we have a integration test for this scenario where we announce key for a root agent

		resp, err := keyCli.AnnounceKey(ctx, &keypb.AnnounceKeyRequest{
			TenantId:   tenantID,
			Kind:       "K1",
			Name:       keyName,
			ParentId:   parentID,
			TargetName: "root",
			Labels:     map[string]string{"cloud": "aws"},
		})


// defaultTestTopology pairs with defaultTestHierarchy and exposes two
// segments: "root" (K0..K0) and "agent" (K1..K3).
func defaultTestTopology() spec.Topology {

@jithinkunjachan jithinkunjachan Jun 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the integration test we don't have root segment but here we have it. IMHO If config are wrong we might have some problems so lets be consistent.
Cause now if we remove the root from the topology

			{Name: testRootName, Segment: spec.HierarchySegment{StartKind: "K0", EndKind: "K0"}},

as we make it similar to the integration test config the test fails for the validation for announcekey(key_service_test.go:76).

topology:
segments:
- name: %s
segment:
start_kind: K2
end_kind: K3
key_bindings:
K2:
vault:
name: agent-vault
type: in-memory
config:
prefix: agent-tek
parent_key_provider:
agent_name: root
K3:
vault:
name: agent-dek-vault
type: in-memory
config:
prefix: agent-dek
selector_labels:
cloud: aws

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I fixed it.

option go_package = "github.com/openkcm/krypton/pkg/api/v1/proto/admin/keys";

service KeyService {
rpc AnnounceKey(AnnounceKeyRequest) returns (AnnounceKeyResponse);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Currently AnnounceKeyRequest don't have --target-selector field will this be added in subsequent PR Or we go for lean approach for the time being.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I was unsure how that will work currently we are using the target name for that. Ideally if we use something like labels we would need to figure out which labels match which agents and then find the agent where the announce will be valid, and then resolve the tasks. This can be done in a future ticket.

Comment thread pkg/api/v1/proto/admin/keys/key_service.go Outdated
Comment thread pkg/api/v1/proto/admin/keys/key_service.go Outdated
Comment thread pkg/api/v1/proto/admin/keys/key_service.go Outdated
Comment thread pkg/api/v1/proto/admin/keys/key_service.go Outdated
Comment thread pkg/api/v1/proto/admin/keys/key_service.go
Signed-off-by: Naman Balaji <namanb487@gmail.com>
Signed-off-by: Naman Balaji <namanb487@gmail.com>
@NamanBalaji NamanBalaji force-pushed the feat/key-request-validator branch from 3b382f0 to 12ac827 Compare June 12, 2026 09:33

@jithinkunjachan jithinkunjachan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice Job

return nil, fmt.Errorf("confirm job: %w", err)
}

if key.KeyProcessingState.JobID != job.ID.String() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good check

@NamanBalaji NamanBalaji merged commit 65731f7 into main Jun 12, 2026
5 checks passed
@NamanBalaji NamanBalaji deleted the feat/key-request-validator branch June 12, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants