Skip to content

Commit 1588233

Browse files
Merge pull request #1687 from 4dn-dcic/utils
July Security Update
2 parents bd58085 + a538c03 commit 1588233

20 files changed

+615
-734
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ jobs:
7777
TRAVIS_JOB_ID: ff-npm-x-test-${{ github.run_number }}-
7878
# This will be the new environment variable name.
7979
TEST_JOB_ID: ff-npm-test-${{ github.run_number }}-
80+
# set global_env_bucket
81+
GLOBAL_ENV_BUCKET: ${{ secrets.GLOBAL_ENV_BUCKET }}
8082
run: |
8183
make remote-test-npm
8284
@@ -102,6 +104,8 @@ jobs:
102104
TRAVIS_JOB_ID: ff-unit-x-test-${{ github.run_number }}-
103105
# This will be the new environment variable name.
104106
TEST_JOB_ID: ff-unit-test-${{ github.run_number }}-
107+
# set global_env_bucket
108+
GLOBAL_ENV_BUCKET: ${{ secrets.GLOBAL_ENV_BUCKET }}
105109
run: |
106110
make remote-test-unit
107111

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ RUN npm ci --no-fund --no-progress --no-optional --no-audit --python=/opt/venv/b
7474
COPY . .
7575

7676
# Build remaining back-end
77-
RUN poetry install && \
77+
RUN poetry install --no-dev -vvv && \
7878
python setup_eb.py develop && \
7979
make fix-dist-info
8080

conftest.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import os
12
import pytest
23
import tempfile
34

5+
from dcicutils.misc_utils import PRINT
6+
7+
48

59
def pytest_addoption(parser):
610
parser.addoption("--es", action="store", default="", dest='es',
@@ -24,3 +28,38 @@ def pytest_configure():
2428
# because without it some of the filenames we generate end up being too long, and critical functionality
2529
# ends up failing. Some socket-related filenames, for example, seem to have length limits. -kmp 5-Jun-2020
2630
tempfile.tempdir = '/tmp'
31+
32+
33+
PRINT("=" * 80)
34+
PRINT("Configuring environment variables...")
35+
36+
my_selected_account = os.environ.get("ACCOUNT_NUMBER")
37+
38+
# TODO: Maybe make this test programmable in env_utils sometime. -kmp 21-Jul-2022
39+
desired_env = 'fourfront-mastertest'
40+
41+
my_selected_env = os.environ.get("ENV_NAME")
42+
43+
if not my_selected_account or my_selected_account == "643366669028":
44+
PRINT("The legacy account is correctly selected for testing Fourfront.")
45+
elif not my_selected_env:
46+
print("ENV_NAME was not set. It is being set to {desired_env}.")
47+
os.environ['ENV_NAME'] = desired_env
48+
elif my_selected_env != desired_env:
49+
PRINT(f"ENV_NAME must be set to {desired_env} (or left unset) for testing. (It is set to {my_selected_env}.)")
50+
exit(1)
51+
else:
52+
PRINT(f"Leaving ENV_NAME set to {desired_env}.")
53+
54+
old_identity = os.environ.get("IDENTITY")
55+
new_identity = 'C4AppConfigFourfrontMastertestApplicationConfigurationfourfrontmastertest'
56+
if old_identity == new_identity:
57+
PRINT(f"IDENTITY is already set to the desired value ({new_identity}). That value will be used.")
58+
elif old_identity:
59+
PRINT(f"IDENTITY is set incompatibly for ENV_NAME={desired_env}.")
60+
exit(1)
61+
else:
62+
PRINT(f"The IDENTITY environment variable is being set to {new_identity} so you can assume its credentials.")
63+
os.environ['IDENTITY'] = new_identity
64+
65+
PRINT("=" * 80)

deploy/docker/production/assume_identity.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
import os
88
import logging
9-
from dcicutils.qa_utils import override_environ
9+
from dcicutils.misc_utils import override_environ
1010
from dcicutils.deployment_utils import BasicOrchestratedFourfrontIniFileManager
1111
from dcicutils.secrets_utils import assume_identity
12+
from dcicutils.env_utils import EnvUtils
1213

1314

1415
logging.basicConfig(level=logging.INFO)
@@ -34,6 +35,8 @@ def build_production_ini_from_global_application_configuration():
3435

3536
# build production.ini
3637
with override_environ(**identity):
38+
# load env_utils
39+
EnvUtils.init()
3740

3841
# TODO: this probably needs configuring but minimal
3942
FourfrontDockerIniFileManager.build_ini_file_from_template(

deploy/docker/production/entrypoint_deployment.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ poetry run python -m assume_identity
99
# Clear db/es on fourfront-mastertest if we run an "initial" deploy
1010
# Do nothing on other environments
1111
if [ -n "${INITIAL_DEPLOYMENT}" ]; then
12-
poetry run clear-db-es-contents production.ini --app-name app --env fourfront_mastertest
12+
poetry run clear-db-es-contents production.ini --app-name app --env fourfront-mastertest
1313
fi
1414

1515
## Create mapping

deploy/docker/production/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ http {
110110
# the below code is a "hack" for doing "if cond1 AND cond2" - Will Oct 14 21
111111
# if we are a *.4dnucleome.org host
112112
set $is_https_host "";
113-
if ($host ~* ((data|mastertest)\.4dnucleome\.org)) {
113+
if ($host ~* ((data|staging|mastertest)\.4dnucleome\.org)) {
114114
set $is_https_host YE;
115115
}
116116

poetry.lock

Lines changed: 336 additions & 515 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
# Note: Various modules refer to this system as "encoded", not "fourfront".
33
name = "encoded"
4-
version = "4.4.17" # 4.0.0 introduced containerization
4+
version = "4.4.18" # 4.0.0 introduced containerization
55
description = "4DN-DCIC Fourfront"
66
authors = ["4DN-DCIC Team <[email protected]>"]
77
license = "MIT"
@@ -37,14 +37,14 @@ classifiers = [
3737

3838
[tool.poetry.dependencies]
3939
python = ">=3.7.1,<3.9"
40-
awscli = ">=1.21.3,!=1.22.52"
41-
boto3 = "^1.21.5"
42-
botocore = "^1.24.5"
40+
awscli = ">=1.25.36"
41+
boto3 = "^1.24.36"
42+
botocore = "^1.27.36"
4343
certifi = ">=2021.5.30"
4444
chardet = "3.0.4"
4545
colorama = "0.3.3"
46-
dcicsnovault = "^5.6.1"
47-
dcicutils = "^3.14.0.2b38"
46+
dcicsnovault = "^6.0.0"
47+
dcicutils = "^4.0.0"
4848
elasticsearch = "6.8.1"
4949
elasticsearch-dsl = "^6.4.0" # TODO: port code from cgap-portal to get rid of uses
5050
execnet = "1.4.1"
@@ -115,8 +115,8 @@ supervisor = "^4.2.4"
115115

116116
[tool.poetry.dev-dependencies]
117117
# PyCharm says boto3-stubs contains useful type hints
118-
botocore-stubs = "^1.24.5"
119-
boto3-stubs = "^1.21.5"
118+
boto3-stubs = "^1.24.36"
119+
botocore-stubs = "^1.27.36"
120120
coverage = ">=6.2"
121121
codacy-coverage = ">=1.3.11"
122122
coveralls = ">=3.3.1"
@@ -161,6 +161,12 @@ wheel = ">=0.29.0" # needed for distribution but not any particular version
161161
# See details at https://pytest.org/en/stable/customize.html
162162

163163
[tool.poetry.scripts]
164+
# dcicutils commands
165+
add-image-tag = "dcicutils.ecr_scripts:add_image_tag_main"
166+
show-global-env-bucket = "dcicutils.env_scripts:show_global_env_bucket_main"
167+
show-image-manifest = "dcicutils.ecr_scripts:show_image_manifest_main"
168+
show-image-catalog = "dcicutils.ecr_scripts:show_image_catalog_main"
169+
unrelease-most-recent-image = "dcicutils.ecr_scripts:unrelease_most_recent_image_main"
164170
# snovault commands
165171
batchupgrade = "snovault.batchupgrade:main"
166172
create-mapping = "snovault.elasticsearch.create_mapping:main"
@@ -195,7 +201,6 @@ spreadsheet-to-json = "encoded.commands.spreadsheet_to_json:main"
195201
update-inserts-from-server = "encoded.commands.update_inserts_from_server:main"
196202
verify-item = "encoded.commands.verify_item:main"
197203

198-
199204
[paste.app_factory]
200205
main = "encoded:main"
201206

src/encoded/__init__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import subprocess
88
import webtest
99

10-
from dcicutils.env_utils import get_mirror_env_from_context, is_stg_or_prd_env
10+
from dcicutils.env_utils import EnvUtils, get_mirror_env_from_context, is_stg_or_prd_env
1111
from dcicutils.ff_utils import get_health_page
1212
from dcicutils.log_utils import set_logging
13+
from dcicutils.secrets_utils import assume_identity
14+
from dcicutils.misc_utils import override_environ
1315
from codeguru_profiler_agent import Profiler
1416
from sentry_sdk.integrations.pyramid import PyramidIntegration
1517
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
@@ -125,6 +127,15 @@ def main(global_config, **local_config):
125127
"""
126128
This function returns a Pyramid WSGI application.
127129
"""
130+
# If running in production (not a unit test or local deploy), assume identity
131+
# and resolve EnvUtils
132+
if not local_config.get('testing', False):
133+
identity = assume_identity()
134+
135+
# Assume GAC and load env utils (once)
136+
with override_environ(**identity):
137+
# load env_utils
138+
EnvUtils.init()
128139

129140
settings = global_config
130141
settings.update(local_config)
@@ -208,7 +219,9 @@ def main(global_config, **local_config):
208219
config.registry['aws_ipset'] = netaddr.IPSet(
209220
record['ip_prefix'] for record in aws_ip_ranges['prefixes'] if record['service'] == 'AMAZON')
210221

211-
if asbool(settings.get('testing', False)):
222+
doing_testing = asbool(settings.get('testing', False))
223+
224+
if doing_testing:
212225
config.include('.tests.testing_views')
213226

214227
# Load upgrades last so that all views (including testing views) are
@@ -220,7 +233,7 @@ def main(global_config, **local_config):
220233
if is_stg_or_prd_env(current_env):
221234
sentry_sdk.init("https://[email protected]/5379985",
222235
integrations=[PyramidIntegration(), SqlalchemyIntegration()])
223-
elif current_env is not None:
236+
elif current_env is not None and not doing_testing:
224237
sentry_sdk.init("https://[email protected]/5373642",
225238
integrations=[PyramidIntegration(), SqlalchemyIntegration()])
226239

src/encoded/commands/create_mapping_on_deploy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _run_create_mapping(app, args):
3737

3838
try:
3939
my_env = get_my_env(app)
40-
deploy_cfg = {'SKIP': True} # default
40+
deploy_cfg = {'SKIP': True, 'ENV_NAME': my_env} # default
4141
if is_beanstalk_env(my_env):
4242
deploy_cfg = CreateMappingOnDeployManager.get_deploy_config(env=my_env, args=args, log=log,
4343
client='create_mapping_on_deploy')
@@ -48,7 +48,7 @@ def _run_create_mapping(app, args):
4848
deploy_cfg['ENV_NAME'] = my_env
4949

5050
# TODO: handle these better
51-
elif my_env in ['fourfront_hotseat', 'fourfront_webdev', 'fourfront_mastertest']:
51+
elif my_env in ['fourfront-hotseat', 'fourfront-webdev', 'fourfront-mastertest']:
5252
deploy_cfg['SKIP'] = False
5353
deploy_cfg['WIPE_ES'] = True
5454
deploy_cfg['STRICT'] = True

0 commit comments

Comments
 (0)