-
Notifications
You must be signed in to change notification settings - Fork 74
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
s3 connector (for data detection & discovery) POC - fides #4930
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3000dae
add s3 connection type; some related reorg for better code sharing
adamsachs 9e28540
add required components list for s3 secrets
adamsachs 4db3d15
migration to add s3 to db connection type enum
adamsachs 22fcac8
bump downrev
adamsachs d53c6de
Merge branch 'main' into asachs/PROD-2098-s3-3d-poc
adamsachs 99c8cc0
bump downrev
adamsachs 1e520fa
support aws assume role; provide a basic s3 connector shell; refactor…
adamsachs 7c8487e
add s3 connection type logo
adamsachs 9d42987
clean up static checks and fix tests
adamsachs d4afd1d
remove unused import
adamsachs 3466682
udpate changelog
adamsachs 7183bf2
s3 connector cleanup
adamsachs 1cfd96f
Merge branch 'main' into asachs/PROD-2098-s3-3d-poc
adamsachs 11d9b63
reconcile connection type migration with new scylla migration from main
adamsachs 42ba44f
fix up broken merge conflict
adamsachs 5133c64
improve aws session logic
adamsachs 1c1c956
Merge branch 'main' into asachs/PROD-2098-s3-3d-poc
adamsachs 1c76a85
fix tests
adamsachs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...des/api/alembic/migrations/versions/2736c942faa2_property_specific_messaging_db_models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/fides/api/alembic/migrations/versions/cb344673f633_add_s3_connection_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""add s3 connection type | ||
|
||
Revision ID: cb344673f633 | ||
Revises: 3304082a6cee | ||
Create Date: 2024-05-31 20:46:08.829330 | ||
|
||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "cb344673f633" | ||
down_revision = "3304082a6cee" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# Add 's3' to ConnectionType enum | ||
op.execute("alter type connectiontype rename to connectiontype_old") | ||
op.execute( | ||
"create type connectiontype as enum('mongodb', 'mysql', 'https', 'snowflake', 'redshift', 'mssql', 'mariadb', 'bigquery', 'saas', 'manual', 'manual_webhook', 'timescale', 'fides', 'sovrn', 'attentive', 'dynamodb', 'postgres', 'generic_consent_email', 'generic_erasure_email', 'scylla', 's3')" | ||
) | ||
op.execute( | ||
( | ||
"alter table connectionconfig alter column connection_type type connectiontype using " | ||
"connection_type::text::connectiontype" | ||
) | ||
) | ||
op.execute("drop type connectiontype_old") | ||
|
||
|
||
def downgrade(): | ||
# Remove 's3' from ConnectionType enum | ||
op.execute("delete from connectionconfig where connection_type in ('s3')") | ||
op.execute("alter type connectiontype rename to connectiontype_old") | ||
op.execute( | ||
"create type connectiontype as enum('mongodb', 'mysql', 'https', 'snowflake', 'redshift', 'mssql', 'mariadb', 'bigquery', 'saas', 'manual', 'manual_webhook', 'timescale', 'fides', 'sovrn', 'attentive', 'dynamodb', 'postgres', 'generic_consent_email', 'generic_erasure_email', 'scylla')" | ||
) | ||
op.execute( | ||
( | ||
"alter table connectionconfig alter column connection_type type connectiontype using " | ||
"connection_type::text::connectiontype" | ||
) | ||
) | ||
op.execute("drop type connectiontype_old") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/fides/api/schemas/connection_configuration/connection_secrets_s3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from typing import Dict, List, Optional | ||
|
||
from pydantic import Field, root_validator | ||
|
||
from fides.api.schemas.base_class import NoValidationSchema | ||
from fides.api.schemas.connection_configuration.connection_secrets import ( | ||
ConnectionConfigSecretsSchema, | ||
) | ||
from fides.api.schemas.storage.storage import AWSAuthMethod | ||
|
||
|
||
class S3Schema(ConnectionConfigSecretsSchema): | ||
"""Schema to validate the secrets needed to connect to Amazon S3""" | ||
|
||
auth_method: AWSAuthMethod = Field( | ||
pattisdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
title="Authentication Method", | ||
description="Determines which type of authentication method to use for connecting to Amazon S3", | ||
) | ||
|
||
aws_access_key_id: Optional[str] = Field( | ||
title="Access Key ID", | ||
description="Part of the credentials that provide access to your AWS account. This is required if using secret key authentication.", | ||
) | ||
aws_secret_access_key: Optional[str] = Field( | ||
title="Secret Access Key", | ||
description="Part of the credentials that provide access to your AWS account. This is required if using secret key authentication.", | ||
sensitive=True, | ||
) | ||
|
||
aws_assume_role_arn: Optional[str] = Field( | ||
pattisdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
title="Assume Role ARN", | ||
description="If provided, the ARN of the role that should be assumed to connect to s3.", | ||
) | ||
Comment on lines
+20
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Schema looks good! From my perspective:
|
||
|
||
_required_components: List[str] = ["auth_method"] | ||
|
||
@root_validator(pre=True) | ||
@classmethod | ||
def keys_provided_if_needed(cls, values: Dict) -> Dict: | ||
""" | ||
Validates that both access and secret access keys are provided if using a `secret_keys` auth method. | ||
""" | ||
if values.get("auth_method") == AWSAuthMethod.SECRET_KEYS.value and not ( | ||
values.get("aws_access_key_id") and values.get("aws_secret_access_key") | ||
): | ||
raise ValueError( | ||
f"An Access Key ID and a Secret Access Key must be provided if using the `{AWSAuthMethod.SECRET_KEYS.value}` Authentication Method" | ||
) | ||
|
||
return values | ||
|
||
|
||
class S3DocsSchema(S3Schema, NoValidationSchema): | ||
"""S3 Secrets Schema for API Docs""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from typing import Any, Dict, List, Optional | ||
|
||
from loguru import logger | ||
|
||
from fides.api.common_exceptions import ConnectionException | ||
from fides.api.graph.execution import ExecutionNode | ||
from fides.api.models.connectionconfig import ConnectionTestStatus | ||
from fides.api.models.policy import Policy | ||
from fides.api.models.privacy_request import PrivacyRequest, RequestTask | ||
from fides.api.schemas.connection_configuration.connection_secrets_s3 import S3Schema | ||
from fides.api.service.connectors.base_connector import BaseConnector | ||
from fides.api.service.connectors.query_config import QueryConfig | ||
from fides.api.util.aws_util import get_aws_session | ||
from fides.api.util.collection_util import Row | ||
|
||
|
||
class S3Connector(BaseConnector): | ||
""" | ||
AWS S3 Connector - this is currently used just to test connections to S3. | ||
|
||
NOTE: No DSR processing is yet supported for S3. | ||
""" | ||
|
||
def create_client(self) -> Any: # type: ignore | ||
"""Returns a client for s3""" | ||
config = S3Schema(**self.configuration.secrets or {}) | ||
pattisdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return get_aws_session( | ||
pattisdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
auth_method=config.auth_method.value, | ||
storage_secrets=config.dict(), # type: ignore | ||
assume_role_arn=config.aws_assume_role_arn, | ||
) | ||
|
||
def query_config(self, node: ExecutionNode) -> QueryConfig[Any]: | ||
"""DSR execution not yet supported for S3""" | ||
raise NotImplementedError() | ||
|
||
def test_connection(self) -> Optional[ConnectionTestStatus]: | ||
""" | ||
Connects to AWS S3 and gets caller identity to validate credentials. | ||
""" | ||
logger.info("Starting test connection to {}", self.configuration.key) | ||
try: | ||
session = self.client() | ||
sts_client = session.client("sts") | ||
sts_client.get_caller_identity() | ||
except Exception as error: | ||
raise ConnectionException(str(error)) | ||
|
||
return ConnectionTestStatus.succeeded | ||
|
||
def retrieve_data( | ||
self, | ||
node: ExecutionNode, | ||
policy: Policy, | ||
privacy_request: PrivacyRequest, | ||
request_task: RequestTask, | ||
input_data: Dict[str, List[Any]], | ||
) -> List[Row]: | ||
"""DSR execution not yet supported for S3""" | ||
|
||
def mask_data( | ||
self, | ||
node: ExecutionNode, | ||
policy: Policy, | ||
privacy_request: PrivacyRequest, | ||
request_task: RequestTask, | ||
rows: List[Row], | ||
) -> int: | ||
"""DSR execution not yet supported for S3""" | ||
|
||
def close(self) -> None: | ||
"""Close any held resources""" | ||
# no held resources for S3 connector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't want to make our changes too wide-ranging quite yet, so i've just put in a note that we should look to switch dynamoDB over to this authentication paradigm soon. dynamoDB does require a region (I think?), so i'm not sure how that changes things. but I still think that provided an option to assume a role will be the right thing to support here moving forward 👍