From 3fe5a7056232bc6538da8d8a350e5f473caad793 Mon Sep 17 00:00:00 2001 From: Ryan Yanulites Date: Tue, 6 May 2025 15:28:38 -0600 Subject: [PATCH 01/17] add migration for new table --- ...d_resources_action_and_attribute_values.md | 18 ++++++++++ ..._resources_action_and_attribute_values.sql | 35 +++++++++++++++++++ service/policy/db/schema_erd.md | 14 +++++++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 service/policy/db/migrations/20250506000000_registered_resources_action_and_attribute_values.md create mode 100644 service/policy/db/migrations/20250506000000_registered_resources_action_and_attribute_values.sql diff --git a/service/policy/db/migrations/20250506000000_registered_resources_action_and_attribute_values.md b/service/policy/db/migrations/20250506000000_registered_resources_action_and_attribute_values.md new file mode 100644 index 0000000000..b5c8fdfb3e --- /dev/null +++ b/service/policy/db/migrations/20250506000000_registered_resources_action_and_attribute_values.md @@ -0,0 +1,18 @@ +# Registered Resources Action and Attribute Values Migration +This migration creates a new table to store the relationship between registered resources, actions, and attribute values. + +```mermaid +erDiagram + registered_resource_values ||--o{ registered_resource_action_attribute_values : has + actions ||--o{ registered_resource_action_attribute_values : has + attribute_values ||--o{ registered_resource_action_attribute_values : has + + registered_resource_action_attribute_values { + UUID id PK + UUID registered_resource_value_id FK + UUID action_id FK + UUID attribute_value_id FK + TIMESTAMP created_at + TIMESTAMP updated_at + } +``` \ No newline at end of file diff --git a/service/policy/db/migrations/20250506000000_registered_resources_action_and_attribute_values.sql b/service/policy/db/migrations/20250506000000_registered_resources_action_and_attribute_values.sql new file mode 100644 index 0000000000..2b5855e9d4 --- /dev/null +++ b/service/policy/db/migrations/20250506000000_registered_resources_action_and_attribute_values.sql @@ -0,0 +1,35 @@ +-- +goose Up +-- +goose StatementBegin + +CREATE TABLE IF NOT EXISTS registered_resource_action_attribute_values ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + registered_resource_value_id UUID NOT NULL REFERENCES registered_resource_values(id) ON DELETE CASCADE, + action_id UUID NOT NULL REFERENCES actions(id) ON DELETE CASCADE, + attribute_value_id UUID NOT NULL REFERENCES attribute_values(id) ON DELETE CASCADE, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + UNIQUE(registered_resource_value_id, action_id, attribute_value_id) +); +COMMENT ON TABLE registered_resource_action_attribute_values IS 'Table to store the linkage of registered resource values to actions and attribute values'; +COMMENT ON COLUMN registered_resource_action_attribute_values.id IS 'Primary key for the table'; +COMMENT ON COLUMN registered_resource_action_attribute_values.registered_resource_value_id IS 'Foreign key to the registered_resource_values table'; +COMMENT ON COLUMN registered_resource_action_attribute_values.action_id IS 'Foreign key to the actions table'; +COMMENT ON COLUMN registered_resource_action_attribute_values.attribute_value_id IS 'Foreign key to the attribute_values table'; +COMMENT ON COLUMN registered_resource_action_attribute_values.created_at IS 'Timestamp when the record was created'; +COMMENT ON COLUMN registered_resource_action_attribute_values.updated_at IS 'Timestamp when the record was last updated'; + +CREATE TRIGGER registered_resource_action_attribute_values_updated_at + BEFORE UPDATE ON registered_resource_action_attribute_values + FOR EACH ROW + EXECUTE FUNCTION update_updated_at(); + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin + +DROP TRIGGER IF EXISTS registered_resource_action_attribute_values_updated_at ON registered_resource_action_attribute_values; + +DROP TABLE IF EXISTS registered_resource_action_attribute_values; + +-- +goose StatementEnd \ No newline at end of file diff --git a/service/policy/db/schema_erd.md b/service/policy/db/schema_erd.md index 1a10e2f270..5530549fe9 100644 --- a/service/policy/db/schema_erd.md +++ b/service/policy/db/schema_erd.md @@ -122,7 +122,7 @@ erDiagram jsonb metadata "Metadata for the KAS (see protos for structure)" character_varying name UK "Optional common name of the KAS" jsonb public_key "Public key of the KAS (see protos for structure/options)" - integer source_type + character_varying source_type timestamp_with_time_zone updated_at character_varying uri UK "URI of the KAS" } @@ -136,6 +136,15 @@ erDiagram timestamp_with_time_zone updated_at "Timestamp when the provider configuration was last updated" } + registered_resource_action_attribute_values { + uuid action_id FK,UK "Foreign key to the actions table" + uuid attribute_value_id FK,UK "Foreign key to the attribute_values table" + timestamp_with_time_zone created_at "Timestamp when the record was created" + uuid id PK "Primary key for the table" + uuid registered_resource_value_id FK,UK "Foreign key to the registered_resource_values table" + timestamp_with_time_zone updated_at "Timestamp when the record was last updated" + } + registered_resource_values { timestamp_with_time_zone created_at "Timestamp when the record was created" uuid id PK "Primary key for the table" @@ -208,6 +217,7 @@ erDiagram timestamp_with_time_zone updated_at "Timestamp when the key was last updated" } + registered_resource_action_attribute_values }o--|| actions : "action_id" subject_mapping_actions }o--|| actions : "action_id" asym_key }o--|| provider_config : "provider_config_id" attribute_definition_key_access_grants }o--|| attribute_definitions : "attribute_definition_id" @@ -228,10 +238,12 @@ erDiagram attribute_value_key_access_grants }o--|| key_access_servers : "key_access_server_id" attribute_value_public_key_map }o--|| attribute_values : "value_id" attribute_value_public_key_map }o--|| key_access_server_keys : "key_access_server_key_id" + registered_resource_action_attribute_values }o--|| attribute_values : "attribute_value_id" resource_mappings }o--|| attribute_values : "attribute_value_id" subject_mappings }o--|| attribute_values : "attribute_value_id" key_access_server_keys }o--|| key_access_servers : "key_access_server_id" sym_key }o--|| provider_config : "provider_config_id" + registered_resource_action_attribute_values }o--|| registered_resource_values : "registered_resource_value_id" registered_resource_values }o--|| registered_resources : "registered_resource_id" resource_mappings }o--|| resource_mapping_groups : "group_id" subject_mappings }o--|| subject_condition_set : "subject_condition_set_id" From 7ff2c1586b595fb330b3ea663764f7d942677883 Mon Sep 17 00:00:00 2001 From: Ryan Yanulites Date: Wed, 7 May 2025 16:42:43 -0600 Subject: [PATCH 02/17] initial implementation for get and create --- docs/grpc/index.html | 112 +++ .../registered_resources.swagger.json | 554 ++++++++++ protocol/go/policy/objects.pb.go | 552 ++++++---- .../registered_resources.pb.go | 945 +++++++++++------- .../integration/registered_resources_test.go | 29 + service/pkg/db/db.go | 1 + service/policy/db/copyfrom.go | 48 + service/policy/db/db.go | 3 +- service/policy/db/models.go | 18 +- service/policy/db/query.sql | 26 +- service/policy/db/query.sql.go | 58 +- service/policy/db/registered_resources.go | 50 + service/policy/objects.proto | 13 + .../registered_resources.proto | 42 + 14 files changed, 1847 insertions(+), 604 deletions(-) create mode 100644 service/policy/db/copyfrom.go diff --git a/docs/grpc/index.html b/docs/grpc/index.html index e83c36c17a..a63c82da8c 100644 --- a/docs/grpc/index.html +++ b/docs/grpc/index.html @@ -269,6 +269,10 @@

Table of Contents

MRegisteredResource +
  • + MRegisteredResourceActionAttributeValue +
  • +
  • MRegisteredResourceValue
  • @@ -1195,6 +1199,10 @@

    Table of Contents

    policy/registeredresources/registered_resources.proto