-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
workerauth: satisfy NodeIdLoader interface #4870
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really cool, thank you!
internal/db/sqltest/tests/server/server_worker_local_storage_state.sql
Outdated
Show resolved
Hide resolved
internal/db/schema/migrations/oss/postgres/88/01_worker_auth_invariant_trigger.up.sql
Outdated
Show resolved
Hide resolved
Database schema diff between To understand how these diffs are generated and some limitations see the Functionsdiff --git a/.schema-diff/funcs_ea9f4b717939eb7d2dc352eeec7eb58a7408e1fe/update_worker_auth_authorized.sql b/.schema-diff/funcs_ea9f4b717939eb7d2dc352eeec7eb58a7408e1fe/update_worker_auth_authorized.sql
new file mode 100644
index 000000000..38f17faae
--- /dev/null
+++ b/.schema-diff/funcs_ea9f4b717939eb7d2dc352eeec7eb58a7408e1fe/update_worker_auth_authorized.sql
@@ -0,0 +1,58 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: update_worker_auth_authorized(); type: function; schema: public; owner: -
+--
+
+create function public.update_worker_auth_authorized() returns trigger
+ language plpgsql
+ as $$
+begin
+ if new.state = 'current' then
+ perform
+ from worker_auth_authorized
+ where state = 'current' and worker_id = new.worker_id and worker_key_identifier != new.worker_key_identifier;
+ if found then
+ raise 'current worker auth already exists; cannot set %s to current', new.worker_key_identifier;
+ end if;
+ end if;
+ if new.state = 'previous' then
+ perform
+ from worker_auth_authorized
+ where state = 'previous' and worker_id = new.worker_id and worker_key_identifier != new.worker_key_identifier;
+ if found then
+ raise 'previous worker auth already exists; cannot set %s to previous', new.worker_key_identifier;
+ end if;
+ end if;
+ return new;
+end;
+$$;
+
+
+--
+-- name: function update_worker_auth_authorized(); type: comment; schema: public; owner: -
+--
+
+comment on function public.update_worker_auth_authorized() is 'update_worker_auth_authorized is a before update trigger function for the worker_auth_authorized table.';
+
+
+--
+-- postgresql database dump complete
+--
+ TablesUnchanged ViewsUnchanged Triggersdiff --git a/.schema-diff/triggers_ea9f4b717939eb7d2dc352eeec7eb58a7408e1fe/worker_auth_authorized update_worker_auth_authorized.sql b/.schema-diff/triggers_ea9f4b717939eb7d2dc352eeec7eb58a7408e1fe/worker_auth_authorized update_worker_auth_authorized.sql
new file mode 100644
index 000000000..a955169ef
--- /dev/null
+++ b/.schema-diff/triggers_ea9f4b717939eb7d2dc352eeec7eb58a7408e1fe/worker_auth_authorized update_worker_auth_authorized.sql
@@ -0,0 +1,29 @@
+--
+-- postgresql database dump
+--
+
+-- dumped from database version 13.15
+-- dumped by pg_dump version 14.12 (ubuntu 14.12-1.pgdg22.04+1)
+
+set statement_timeout = 0;
+set lock_timeout = 0;
+set idle_in_transaction_session_timeout = 0;
+set client_encoding = 'utf8';
+set standard_conforming_strings = on;
+select pg_catalog.set_config('search_path', '', false);
+set check_function_bodies = false;
+set xmloption = content;
+set client_min_messages = warning;
+set row_security = off;
+
+--
+-- name: worker_auth_authorized update_worker_auth_authorized; type: trigger; schema: public; owner: -
+--
+
+create trigger update_worker_auth_authorized before update on public.worker_auth_authorized for each row execute function public.update_worker_auth_authorized();
+
+
+--
+-- postgresql database dump complete
+--
+ IndexesUnchanged ConstraintsUnchanged Foreign Key ConstraintsUnchanged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤞🏻 would love to have Jeffs review on this as well but LGTM!
Note: tests will fail until the corresponding nodeenrollment changes are merged
Changes to the worker auth repository:
LoadByNodeId
Also added a database trigger to ensure we don't store multiple current or previous records for a worker