Skip to content

Add created_by_user to cluster_agent_tokens

Emily Ring requested to merge 293720-token-created-by into master

What does this MR do?

We want to track and display the user that creates a Clusters::AgentToken

See related issue: #293720 (closed)

This MR will:

  • Add created_by_user fields to the database and Clusters::AgentToken model
  • Update Clusters::AgentTokens::CreateService to include user information
  • Update GraphQL to display new created_by_user field
  • Update associated tests and docs

Screenshots (strongly suggested)

token

Migrations

up

== 20210211195543 AddCreatedByUserForClusterAgentToken: migrating =============
-- column_exists?(:cluster_agent_tokens, :created_by_user_id)
   -> 0.0016s
-- add_column(:cluster_agent_tokens, :created_by_user_id, :bigint)
   -> 0.0014s
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:cluster_agent_tokens, :created_by_user_id, {:name=>"index_cluster_agent_tokens_on_created_by_user_id", :algorithm=>:concurrently})
   -> 0.0022s
-- execute("SET statement_timeout TO 0")
   -> 0.0004s
-- add_index(:cluster_agent_tokens, :created_by_user_id, {:name=>"index_cluster_agent_tokens_on_created_by_user_id", :algorithm=>:concurrently})
   -> 0.0058s
-- execute("RESET ALL")
   -> 0.0005s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:cluster_agent_tokens)
   -> 0.0030s
-- execute("ALTER TABLE cluster_agent_tokens\nADD CONSTRAINT fk_75008f3553\nFOREIGN KEY (created_by_user_id)\nREFERENCES users (id)\nON DELETE SET NULL\nNOT VALID;\n")
   -> 0.0018s
-- execute("ALTER TABLE cluster_agent_tokens VALIDATE CONSTRAINT fk_75008f3553;")
   -> 0.0029s
== 20210211195543 AddCreatedByUserForClusterAgentToken: migrated (0.0259s) ====

down

== 20210211195543 AddCreatedByUserForClusterAgentToken: reverting =============
-- foreign_keys(:cluster_agent_tokens)
   -> 0.0026s
-- remove_foreign_key(:cluster_agent_tokens, :users, {:column=>:created_by_user_id})
   -> 0.0033s
-- transaction_open?()
   -> 0.0000s
-- indexes(:cluster_agent_tokens)
   -> 0.0028s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- remove_index(:cluster_agent_tokens, {:algorithm=>:concurrently, :name=>"index_cluster_agent_tokens_on_created_by_user_id"})
   -> 0.0033s
-- execute("RESET ALL")
   -> 0.0005s
-- remove_column(:cluster_agent_tokens, :created_by_user_id)
   -> 0.0012s
== 20210211195543 AddCreatedByUserForClusterAgentToken: reverted (0.0200s) ====

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #293720 (closed)

Edited by Emily Ring

Merge request reports