Skip to content

Commit a83a6e7

Browse files
committed
updated deps, restored migrations
1 parent 2cb7f84 commit a83a6e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2252
-68
lines changed

generate_tokens.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Helper script to generate random values for Lemur configuration
33
"""
4-
from base64 import urlsafe_b64encode
4+
from base64 import urlsafe_b64encode, b64encode
55
from os import urandom
66
from secrets import choice, token_hex
77
from string import ascii_lowercase, ascii_uppercase, digits
@@ -11,3 +11,5 @@
1111
print("LEMUR_ENCRYPTION_KEY:", urlsafe_b64encode(urandom(32)).decode())
1212
print("LEMUR_TOKEN_SECRET:", ''.join(choice(chars) for x in range(24)))
1313
print("SECRET:", token_hex())
14+
print("OAUTH2_SECRET:", token_hex())
15+
print("OAUTH_STATE_TOKEN_SECRET:", b64encode(urandom(32)))

lemur.conf.py

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
LEMUR_TOKEN_SECRETS = [LEMUR_TOKEN_SECRET]
3232
LEMUR_ENCRYPTION_KEYS = ['Q7AzDsZHJRaKdS4Obeb4bLw6tYRdTqQD24xHQqJbA4A=']
3333

34+
35+
OAUTH2_SECRET = 'd105a7b3f365423a08917fa0455b353fce966e955c3a6e88f8ff149fac301a03'
36+
37+
# this is the secret used to generate oauth state tokens
38+
OAUTH_STATE_TOKEN_SECRET = b'jhyNmgizEixQRnWL8F9yTfGlKz3pp2ks2GGxAUoFYE8='
39+
3440
# REQUIRED
3541
# Certificate Defaults
3642
LEMUR_DEFAULT_COUNTRY = ""
@@ -40,6 +46,25 @@
4046
LEMUR_DEFAULT_ORGANIZATIONAL_UNIT = ""
4147
LEMUR_SECURITY_TEAM_EMAIL = ["admin@localhost"]
4248

49+
DIGICERT_CIS_API_KEY=""
50+
DIGICERT_API_KEY=""
51+
ENTRUST_API_USER=""
52+
GOOGLE_APPLICATION_CREDENTIALS=""
53+
DIGICERT_CIS_URL=""
54+
DIGICERT_URL=""
55+
ENTRUST_API_PASS=""
56+
DIGICERT_CIS_ROOTS=""
57+
DIGICERT_ORG_ID=""
58+
ENTRUST_URL=""
59+
DIGICERT_CIS_PROFILE_NAMES=""
60+
DIGICERT_ORDER_TYPE=""
61+
ENTRUST_ROOT=""
62+
ENTRUST_NAME=""
63+
DIGICERT_ROOT=""
64+
ENTRUST_EMAIL=""
65+
ENTRUST_PHONE=""
66+
67+
4368
# Database settings
4469
SQLALCHEMY_DATABASE_URI = environ.get('SQLALCHEMY_DATABASE_URI', 'postgresql://lemur:lemur@localhost:5432/lemur')
4570
# SQLALCHEMY_ENABLE_FLASK_REPLICATED = False
@@ -77,22 +102,19 @@
77102
# VERISIGN_LAST_NAME = ""
78103
# VERSIGN_EMAIL = ""
79104

80-
IDP_GROUPS_KEYS = ["googleGroups"] # a list of keys used by IDP(s) to return user groups (profile[IDP_GROUPS_KEY])
81-
# Note that prefix/suffix can be commented out or set to "" if no filtering against naming convention is desired
82-
# IDP_ROLES_PREFIX = "PREFIX-" # prefix for all IDP-defined roles, used to match naming conventions
83-
# IDP_ROLES_SUFFIX = "_SUFFIX" # suffix for all IDP-defined roles, used to match naming conventions
84-
# IDP_ROLES_DESCRIPTION = "Automatically generated role" # Description to attach to automatically generated roles
85-
# IDP_ROLES_MAPPING = {} # Dictionary that matches the IDP group name to the Lemur role. The Lemur role must exist.
86-
# Example: IDP_ROLES_MAPPING = {"security": "admin", "engineering": "operator", "jane_from_accounting": "read-only"}
87-
IDP_ASSIGN_ROLES_FROM_USER_GROUPS = True # Assigns a Lemur role for each group found attached to the user
88-
IDP_CREATE_ROLES_FROM_USER_GROUPS = True # Creates a Lemur role for each group found attached to the user if missing
89-
# Protects the built-in groups and prevents dynamically assigning users to them. Prevents IDP admin from becoming
90-
# Lemur admin. Use IDP_ROLES_MAPPING to create a mapping to assign these groups if desired. eg {"admin": "admin"}
91-
IDP_PROTECT_BUILTINS = True
92-
IDP_CREATE_PER_USER_ROLE = True # Generates Lemur role for each user (allows cert assignment to a single user)
93-
94-
# # this is the secret used to generate oauth state tokens
95-
# OAUTH_STATE_TOKEN_SECRET = repr(environ.get('OAUTH_STATE_TOKEN_SECRET', '')
105+
# IDP_GROUPS_KEYS = ["googleGroups"] # a list of keys used by IDP(s) to return user groups (profile[IDP_GROUPS_KEY])
106+
# # Note that prefix/suffix can be commented out or set to "" if no filtering against naming convention is desired
107+
# # IDP_ROLES_PREFIX = "PREFIX-" # prefix for all IDP-defined roles, used to match naming conventions
108+
# # IDP_ROLES_SUFFIX = "_SUFFIX" # suffix for all IDP-defined roles, used to match naming conventions
109+
# # IDP_ROLES_DESCRIPTION = "Automatically generated role" # Description to attach to automatically generated roles
110+
# # IDP_ROLES_MAPPING = {} # Dictionary that matches the IDP group name to the Lemur role. The Lemur role must exist.
111+
# # Example: IDP_ROLES_MAPPING = {"security": "admin", "engineering": "operator", "jane_from_accounting": "read-only"}
112+
# IDP_ASSIGN_ROLES_FROM_USER_GROUPS = True # Assigns a Lemur role for each group found attached to the user
113+
# IDP_CREATE_ROLES_FROM_USER_GROUPS = True # Creates a Lemur role for each group found attached to the user if missing
114+
# # Protects the built-in groups and prevents dynamically assigning users to them. Prevents IDP admin from becoming
115+
# # Lemur admin. Use IDP_ROLES_MAPPING to create a mapping to assign these groups if desired. eg {"admin": "admin"}
116+
# IDP_PROTECT_BUILTINS = True
117+
# IDP_CREATE_PER_USER_ROLE = True # Generates Lemur role for each user (allows cert assignment to a single user)
96118

97119
# REDIS_HOST = 'redis'
98120
# REDIS_PORT = 6379

lemur/migrations/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

lemur/migrations/alembic.ini

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# template used to generate migration files
5+
# file_template = %%(rev)s_%%(slug)s
6+
7+
# set to 'true' to run the environment during
8+
# the 'revision' command, regardless of autogenerate
9+
# revision_environment = false
10+
11+
12+
# Logging configuration
13+
[loggers]
14+
keys = root,sqlalchemy,alembic
15+
16+
[handlers]
17+
keys = console
18+
19+
[formatters]
20+
keys = generic
21+
22+
[logger_root]
23+
level = WARN
24+
handlers = console
25+
qualname =
26+
27+
[logger_sqlalchemy]
28+
level = WARN
29+
handlers =
30+
qualname = sqlalchemy.engine
31+
32+
[logger_alembic]
33+
level = INFO
34+
handlers =
35+
qualname = alembic
36+
37+
[handler_console]
38+
class = StreamHandler
39+
args = (sys.stderr,)
40+
level = NOTSET
41+
formatter = generic
42+
43+
[formatter_generic]
44+
format = %(levelname)-5.5s [%(name)s] %(message)s
45+
datefmt = %H:%M:%S

lemur/migrations/env.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from alembic import context
2+
from sqlalchemy import engine_from_config, pool
3+
from logging.config import fileConfig
4+
5+
import alembic_autogenerate_enums
6+
7+
8+
# this is the Alembic Config object, which provides
9+
# access to the values within the .ini file in use.
10+
config = context.config
11+
12+
# Interpret the config file for Python logging.
13+
# This line sets up loggers basically.
14+
if config.config_file_name:
15+
fileConfig(config.config_file_name)
16+
17+
# add your model's MetaData object here
18+
# for 'autogenerate' support
19+
# from myapp import mymodel
20+
# target_metadata = mymodel.Base.metadata
21+
from flask import current_app
22+
23+
db_url_escaped = current_app.config.get('SQLALCHEMY_DATABASE_URI', 'postgresql://lemur:lemur@localhost:5432/lemur').replace('%', '%%')
24+
config.set_main_option(
25+
"sqlalchemy.url", db_url_escaped
26+
)
27+
target_metadata = current_app.extensions["migrate"].db.metadata
28+
29+
# other values from the config, defined by the needs of env.py,
30+
# can be acquired:
31+
# my_important_option = config.get_main_option("my_important_option")
32+
# ... etc.
33+
34+
35+
def run_migrations_offline():
36+
"""Run migrations in 'offline' mode.
37+
38+
This configures the context with just a URL
39+
and not an Engine, though an Engine is acceptable
40+
here as well. By skipping the Engine creation
41+
we don't even need a DBAPI to be available.
42+
43+
Calls to context.execute() here emit the given string to the
44+
script output.
45+
46+
"""
47+
url = config.get_main_option("sqlalchemy.url")
48+
context.configure(url=url)
49+
50+
with context.begin_transaction():
51+
context.run_migrations()
52+
53+
54+
def run_migrations_online():
55+
"""Run migrations in 'online' mode.
56+
57+
In this scenario we need to create an Engine
58+
and associate a connection with the context.
59+
60+
"""
61+
engine = engine_from_config(
62+
config.get_section(config.config_ini_section),
63+
prefix="sqlalchemy.",
64+
poolclass=pool.NullPool,
65+
)
66+
67+
connection = engine.connect()
68+
context.configure(
69+
connection=connection,
70+
target_metadata=target_metadata,
71+
**current_app.extensions["migrate"].configure_args
72+
)
73+
74+
try:
75+
with context.begin_transaction():
76+
context.run_migrations()
77+
finally:
78+
connection.close()
79+
80+
81+
if context.is_offline_mode():
82+
run_migrations_offline()
83+
else:
84+
run_migrations_online()

lemur/migrations/script.py.mako

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision}
5+
Create Date: ${create_date}
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = ${repr(up_revision)}
11+
down_revision = ${repr(down_revision)}
12+
13+
from alembic import op
14+
import sqlalchemy as sa
15+
${imports if imports else ""}
16+
17+
def upgrade():
18+
${upgrades if upgrades else "pass"}
19+
20+
21+
def downgrade():
22+
${downgrades if downgrades else "pass"}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Ensuring we have endpoint updated times and certificate rotation availability.
2+
3+
Revision ID: 131ec6accff5
4+
Revises: e3691fc396e9
5+
Create Date: 2016-12-07 17:29:42.049986
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = "131ec6accff5"
11+
down_revision = "e3691fc396e9"
12+
13+
from alembic import op
14+
import sqlalchemy as sa
15+
16+
17+
def upgrade():
18+
# ### commands auto generated by Alembic - please adjust! ###
19+
op.add_column(
20+
"certificates",
21+
sa.Column("rotation", sa.Boolean(), nullable=False, server_default=sa.false()),
22+
)
23+
op.add_column(
24+
"endpoints",
25+
sa.Column(
26+
"last_updated",
27+
sa.DateTime(),
28+
server_default=sa.text("now()"),
29+
nullable=False,
30+
),
31+
)
32+
# ### end Alembic commands ###
33+
34+
35+
def downgrade():
36+
# ### commands auto generated by Alembic - please adjust! ###
37+
op.drop_column("endpoints", "last_updated")
38+
op.drop_column("certificates", "rotation")
39+
# ### end Alembic commands ###
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Adds the endpoint_dnsalias table to store CloudFront distribution aliases.
2+
3+
Revision ID: 189e5fda5bf8
4+
Revises: 2201c548a5a1
5+
Create Date: 2021-10-25 19:52:44.133743
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = '189e5fda5bf8'
11+
down_revision = '2201c548a5a1'
12+
13+
from alembic import op
14+
import sqlalchemy as sa
15+
16+
17+
def upgrade():
18+
# ### commands auto generated by Alembic - please adjust! ###
19+
op.create_table('endpoint_dnsalias',
20+
sa.Column('id', sa.Integer(), nullable=False),
21+
sa.Column('endpoint_id', sa.Integer(), nullable=True),
22+
sa.Column('alias', sa.String(length=256), nullable=True),
23+
sa.ForeignKeyConstraint(['endpoint_id'], ['endpoints.id'], ),
24+
sa.PrimaryKeyConstraint('id')
25+
)
26+
# ### end Alembic commands ###
27+
28+
29+
def downgrade():
30+
# ### commands auto generated by Alembic - please adjust! ###
31+
op.drop_table('endpoint_dnsalias')
32+
# ### end Alembic commands ###
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Adds additional ENUM for creating and updating certificates.
2+
3+
Revision ID: 1ae8e3104db8
4+
Revises: a02a678ddc25
5+
Create Date: 2017-07-13 12:32:09.162800
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = "1ae8e3104db8"
11+
down_revision = "a02a678ddc25"
12+
13+
from alembic import op
14+
15+
16+
def upgrade():
17+
op.sync_enum_values(
18+
"public", "log_type", ["key_view"], ["create_cert", "key_view", "update_cert"]
19+
)
20+
21+
22+
def downgrade():
23+
op.sync_enum_values(
24+
"public", "log_type", ["create_cert", "key_view", "update_cert"], ["key_view"]
25+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Add default rotation_policy to certs where it's missing
2+
3+
Revision ID: 1db4f82bc780
4+
Revises: 3adfdd6598df
5+
Create Date: 2018-08-03 12:56:44.565230
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = "1db4f82bc780"
11+
down_revision = "3adfdd6598df"
12+
13+
from alembic import op
14+
15+
from flask import current_app
16+
from logging import Formatter, FileHandler, getLogger
17+
18+
log = getLogger(__name__)
19+
handler = FileHandler(current_app.config.get("LOG_UPGRADE_FILE", "db_upgrade.log"))
20+
handler.setFormatter(
21+
Formatter(
22+
"%(asctime)s %(levelname)s: %(message)s " "[in %(pathname)s:%(lineno)d]"
23+
)
24+
)
25+
handler.setLevel(current_app.config.get("LOG_LEVEL", "DEBUG"))
26+
log.setLevel(current_app.config.get("LOG_LEVEL", "DEBUG"))
27+
log.addHandler(handler)
28+
29+
30+
def upgrade():
31+
connection = op.get_bind()
32+
33+
result = connection.execute(
34+
"""\
35+
UPDATE certificates
36+
SET rotation_policy_id=(SELECT id FROM rotation_policies WHERE name='default')
37+
WHERE rotation_policy_id IS NULL
38+
RETURNING id
39+
"""
40+
)
41+
log.info("Filled rotation_policy for %d certificates" % result.rowcount)
42+
43+
44+
def downgrade():
45+
pass

0 commit comments

Comments
 (0)