Skip to content
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

[Gh 998] Maintenance window #1236

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

TejasRGitHub
Copy link
Contributor

Feature or Bugfix

  • Feature

Detail

Instructions on using maintenance window

  1. Include yourself in the "DAAdministrators" group.
  2. Goto Admin Section
  3. Switch to Maintenance Tab
  4. You can put data.all in Read-only mode or No-access mode. Select either mode and click on "Start Maintenance" window button
  5. Once the status of the maintenance window is in ACTIVE state. You can be sure that the all ECS tasks have completed runnning and also the scheduled ECS tasks are turned OFF. ( Check this in AWS accounts for testing )
  6. If in Read-only mode, then a red banner will appear whenever any user visits data.all UI . In Read-Only mode, all mutation calls ( are blocked )
  7. If in No-Access mode, then after login a blank page displaying message about data.all maintenance window will appear. In No-Access mode, all graphQL calls are blocked ( Except getGroupForUser and getMaintenanceWindowStatus - which are required for the UI to load minimally).
  8. In order to disable maintenance window, goto the maintenance tab and click stop maintenance window.

Note- In all the mode, data.all admin user is allowed to perform any gql call and access and modify anything on the UI.

Relates

Security

Please answer the questions below briefly where applicable, or write N/A. Based on
OWASP 10.

  • Does this PR introduce or modify any input fields or queries - this includes
    fetching data from storage outside the application (e.g. a database, an S3 bucket)? N/A
    • Is the input sanitized?
    • What precautions are you taking before deserializing the data you consume?
    • Is injection prevented by parametrizing queries?
    • Have you ensured no eval or similar functions are used?
  • Does this PR introduce any functionality or component that requires authorization? N/A
    • How have you ensured it respects the existing AuthN/AuthZ mechanisms?
    • Are you logging failed auth attempts?
  • Are you using or adding any cryptographic features? N/A
    • Do you use a standard proven implementations?
    • Are the used keys controlled by the customer? Where are they stored?
  • Are you introducing any new policies/roles/users? Yes
    • Have you used the least-privilege principle? How? Least Privelege

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@TejasRGitHub TejasRGitHub marked this pull request as ready for review April 30, 2024 18:48
backend/api_handler.py Outdated Show resolved Hide resolved
backend/dataall/base/utils/api_handler_utils.py Outdated Show resolved Hide resolved
# Disable scheduled ECS tasks
# Get all the SSM Params related to the scheduled tasks
ecs_scheduled_rules = ParameterStoreManager.get_parameters_by_path(
region=os.getenv('AWS_REGION', 'eu-west-1'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we really have a default value of eu-west-1 here? Seems like there should be no default and that we check region value and error if it is not a valid region.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am taking the default value from the other similar boto3 wrappers which are defined in dataall/base/aws/ folder. I am in agreement that we should through error if the AWS_REGION env var is nt set. Maybe we should do it for other boto wrappers.

@dlpzx , what are you views ? Is there any particular reason to keep the eu-west-1

)
logger.debug(ecs_scheduled_rules)
ecs_scheduled_rules_list = [item['Value'] for item in ecs_scheduled_rules]
event_bridge_session = EventBridge(region=os.getenv('AWS_REGION', 'eu-west-1'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, curious why we would default to eu-west-1 here.

)
# Enable scheduled ECS tasks
ecs_scheduled_rules = ParameterStoreManager.get_parameters_by_path(
region=os.getenv('AWS_REGION', 'eu-west-1'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question about default region as above.

)
logger.debug(ecs_scheduled_rules)
ecs_scheduled_rules_list = [item['Value'] for item in ecs_scheduled_rules]
event_bridge_session = EventBridge(region=os.getenv('AWS_REGION', 'eu-west-1'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question about default region as above.

if maintenance_record.status == MaintenanceStatus.PENDING.value:
# Check if ECS tasks are running
ecs_cluster_name = ParameterStoreManager.get_parameter_value(
region=os.getenv('AWS_REGION', 'eu-west-1'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question about default region as above.

frontend/src/design/components/layout/DefaultNavbar.js Outdated Show resolved Hide resolved
)
elif (
(maintenance_mode == MaintenanceModes.READONLY.value)
and (maintenance_status is not MaintenanceStatus.INACTIVE.value)
Copy link
Contributor

Choose a reason for hiding this comment

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

MaintenanceStatus.INACTIVE is an enum, so you should compare directly with the enum instead of its value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maintenance_status contains the value of the MaintenanceStatus.INACTIVE enum. Let me check if I can get an enum there instead

@TejasRGitHub
Copy link
Contributor Author

TejasRGitHub commented May 14, 2024

I think this feature should be covered by the new integration tests

For now, I have added the tests in the tests/modules/maintenance.

For the integration tests, i think they are using the cognito idp to authenticate. As we use our custom auth, I don't think I can add tests easily. I think this could be a part of another PR where-in the same integration tests can be run with a custom IDP user

@TejasRGitHub
Copy link
Contributor Author

Updated code

Tested -
Local dev UI and sanity checks - ✅
AWS deployed data.all - Tested for READ-ONLY and NO-ACCESS modes - ✅

from dataall.core.permissions.services.tenant_policy_service import TenantPolicyValidationService

logger = logging.getLogger()
logger.setLevel(os.environ.get('LOG_LEVEL', 'INFO'))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this used for? We are using "log" everywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean why are we using the setLevel command ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the setLevel method is used mostly at the top of logger initialization. I am adding it here to set the log level to whatever is set for each lambda in their environment variable - which is available via the os.environ.get('LOG_LEVEL', 'INFO').

logger.error('Maintenance window already in INACTIVE state. Cannot stop maintenance window')
return False
MaintenanceRepository(session).save_maintenance_status_and_mode(
maintenance_status='INACTIVE', maintenance_mode=''
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Maintenence Enum instead of hardcoded INACTIVE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the next update

@return: returns True if successful or False
"""
# Check from the context if the groups contains the DAAAdminstrators group
groups = get_context().groups if get_context().groups is not None else []
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought get_context().groups returned an empty list when the user belonged to no group.... good finding

Copy link
Contributor

Choose a reason for hiding this comment

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

groups: list = extract_groups(user_id, claims)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is been used only for initializing the groups list when the API handler is called. This takes in the claims which come from the cognito/custom authorizer

Copy link
Contributor Author

@TejasRGitHub TejasRGitHub left a comment

Choose a reason for hiding this comment

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

updated code

'Access-Control-Allow-Methods': '*',
},
'body': json.dumps(response),
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created GH issue - #1302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants