Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Conversation

@atanasovskib
Copy link
Contributor

@atanasovskib atanasovskib commented Apr 30, 2020

The prom_reader and prom_writer roles are created
and granted specific access to all the different schemas,
tables and functions. prom_writer inherits from prom_reader.
prom_reader has read-only access.

The prom_reader and prom_writer roles are created
and granted specific access to all the different schemas,
tables and functions. prom_writer inherits from prom_reader.
prom_reader has read-only access.
Copy link
Contributor

@cevian cevian left a comment

Choose a reason for hiding this comment

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

Some comments, mostly look good.

GRANT USAGE ON SCHEMA SCHEMA_CATALOG TO prom_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA SCHEMA_CATALOG TO prom_reader;
ALTER DEFAULT PRIVILEGES IN SCHEMA SCHEMA_CATALOG GRANT SELECT ON TABLES TO prom_reader;
GRANT CREATE ON SCHEMA SCHEMA_CATALOG TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be an admin thing. A writer is only for writing prom data it does not need to add catalog tables.

GRANT SELECT ON ALL TABLES IN SCHEMA SCHEMA_CATALOG TO prom_reader;
ALTER DEFAULT PRIVILEGES IN SCHEMA SCHEMA_CATALOG GRANT SELECT ON TABLES TO prom_reader;
GRANT CREATE ON SCHEMA SCHEMA_CATALOG TO prom_writer;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA SCHEMA_CATALOG TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Privileges should be SELECT, INSERT, UPDATE, DELETE not all. Same on line below


CREATE SCHEMA IF NOT EXISTS SCHEMA_PROM; -- data tables + public functions
GRANT USAGE ON SCHEMA SCHEMA_PROM TO prom_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA SCHEMA_PROM TO prom_reader;
Copy link
Contributor

Choose a reason for hiding this comment

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

actually there are no tables in here any more (need too change comment) so I think this should just be USAGE on the schema for both reader and writer


CREATE SCHEMA IF NOT EXISTS SCHEMA_EXT; -- optimized versions of functions created by the extension
GRANT USAGE ON SCHEMA SCHEMA_EXT TO prom_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA SCHEMA_EXT TO prom_reader;
Copy link
Contributor

Choose a reason for hiding this comment

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

again no tables in here so we just need usage for both reader and writer.

GRANT SELECT ON ALL TABLES IN SCHEMA SCHEMA_SERIES TO prom_reader;
ALTER DEFAULT PRIVILEGES IN SCHEMA SCHEMA_SERIES GRANT SELECT ON TABLES TO prom_reader;
GRANT CREATE ON SCHEMA SCHEMA_SERIES TO prom_writer;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA SCHEMA_SERIES TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

should probably be SELECT only since these are just views

LANGUAGE SQL VOLATILE;
COMMENT ON FUNCTION SCHEMA_PROM.set_default_retention_period(INTERVAL)
IS 'set the retention period for any metrics (existing and new) without an explicit override';
GRANT EXECUTE ON FUNCTION SCHEMA_PROM.set_default_retention_period(INTERVAL) TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be an admin func

SELECT true;
$func$
LANGUAGE SQL VOLATILE;
GRANT EXECUTE ON FUNCTION SCHEMA_PROM.set_metric_retention_period(TEXT, INTERVAL) TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

admin function

LANGUAGE SQL VOLATILE;
COMMENT ON FUNCTION SCHEMA_PROM.reset_metric_retention_period(TEXT)
IS 'resets the retention period for a specific metric to using the default';
GRANT EXECUTE ON FUNCTION SCHEMA_PROM.reset_metric_retention_period(TEXT) TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

admin func

END
$func$
LANGUAGE PLPGSQL VOLATILE;
GRANT EXECUTE ON FUNCTION SCHEMA_CATALOG.drop_metric_chunks(TEXT, TIMESTAMPTZ) TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

admin func

$$ LANGUAGE PLPGSQL;
COMMENT ON PROCEDURE SCHEMA_PROM.drop_chunks()
IS 'drops data according to the data retention policy. This procedure should be run regularly in a cron job';
GRANT EXECUTE ON PROCEDURE SCHEMA_PROM.drop_chunks() TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

admin func

Copy link
Contributor

@davidkohn88 davidkohn88 left a comment

Choose a reason for hiding this comment

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

This looks good. I don't know whether we also need to modify grants in the extension bit though?

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA SCHEMA_INFO TO prom_writer;
ALTER DEFAULT PRIVILEGES IN SCHEMA SCHEMA_INFO GRANT ALL PRIVILEGES ON TABLES TO prom_writer;

GRANT prom_reader TO prom_writer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't horribly matter, but I'd put the grant of prom reader to prom writer right after you create the roles, just makes everything else make more sense.

@atanasovskib atanasovskib force-pushed the create-access-roles branch from 10c9b9d to a329015 Compare May 1, 2020 11:56
@atanasovskib
Copy link
Contributor Author

Committed changes per comment suggestions. Additionally:

  1. Also assumed set_chunk_interval functions are admin as set_retention
  2. Granted only select on SCHEMA_METRIC since it has only views as SCHEMA_SERIES

@atanasovskib atanasovskib changed the title WIP: Craete read and write access level roles and give grants Craete read and write access level roles and give grants May 1, 2020
@atanasovskib atanasovskib changed the title Craete read and write access level roles and give grants Create read and write access level roles and give grants May 1, 2020
Copy link
Contributor

@cevian cevian left a comment

Choose a reason for hiding this comment

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

Looks good. I will want some of our integration test to run as users for prom_reader and prom_writer users. But I'll leave it up to you if that should be part of this or a a separate PR. Also, I think some of the commits can be squashed before merge.

@atanasovskib atanasovskib merged commit 02eb5aa into master May 4, 2020
@atanasovskib atanasovskib deleted the create-access-roles branch May 4, 2020 14:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants