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

Merged
merged 40 commits into from
Jun 4, 2024

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
@TejasRGitHub TejasRGitHub requested review from dlpzx and petrkalos May 14, 2024 22:50
@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').

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

Copy link
Contributor

@dlpzx dlpzx 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 was a bit unsure about how the maintenance mode disabled was going to behave in the frontend. My concern was that the import import { MaintenanceViewer } from '../../Maintenance/components/MaintenanceViewer'; in frontend/src/modules/Administration/views/AdministrationView.js was going to result in errors, but I tested it locally and because it is not used in the tabs it works normal.

If we wanted to be ultra-clean we would check if (isModuleEnabled(ModuleNames.MAINTENANCE)) before importing and using the MaintenanceViewer, but this is not required.

Approving!

@dlpzx dlpzx merged commit 2801125 into data-dot-all:main Jun 4, 2024
10 checks passed
noah-paige added a commit that referenced this pull request Jun 11, 2024
### Feature or Bugfix
<!-- please choose -->
- Bugfix

### Detail
- Fixes hanging UI render on frontend introduced by AuthGuard useClient
hook for Cognito Auth only

### Relates
- Continuation of #1236 

Thanks @TejasRGitHub for your help here! 

### Security
Please answer the questions below briefly where applicable, or write
`N/A`. Based on
[OWASP 10](https://owasp.org/Top10/en/).

- 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)?
  - 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?
- 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?
  - 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?
  - Have you used the least-privilege principle? How?


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
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.

5 participants