Metadata-Version: 2.4
Name: security-lake-tools
Version: 0.1.1
Summary: Tools for managing AWS Security Lake custom sources
Project-URL: Homepage, https://github.com/tenzir/security-lake-tools
Project-URL: Repository, https://github.com/tenzir/security-lake-tools
Project-URL: Issues, https://github.com/tenzir/security-lake-tools/issues
Project-URL: Documentation, https://github.com/tenzir/security-lake-tools#readme
Author-email: Tenzir <engineering@tenzir.com>
License: Apache License
        Version 2.0, January 2004
        http://www.apache.org/licenses/
        
        TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
        1. Definitions.
        
        "License" shall mean the terms and conditions for use, reproduction,
        and distribution as defined by Sections 1 through 9 of this document.
        
        "Licensor" shall mean the copyright owner or entity authorized by
        the copyright owner that is granting the License.
        
        "Legal Entity" shall mean the union of the acting entity and all
        other entities that control, are controlled by, or are under common
        control with that entity. For the purposes of this definition,
        "control" means (i) the power, direct or indirect, to cause the
        direction or management of such entity, whether by contract or
        otherwise, or (ii) ownership of fifty percent (50%) or more of the
        outstanding shares, or (iii) beneficial ownership of such entity.
        
        "You" (or "Your") shall mean an individual or Legal Entity
        exercising permissions granted by this License.
        
        "Source" form shall mean the preferred form for making modifications,
        including but not limited to software source code, documentation
        source, and configuration files.
        
        "Object" form shall mean any form resulting from mechanical
        transformation or translation of a Source form, including but
        not limited to compiled object code, generated documentation,
        and conversions to other media types.
        
        "Work" shall mean the work of authorship, whether in Source or
        Object form, made available under the License, as indicated by a
        copyright notice that is included in or attached to the work
        (an example is provided in the Appendix below).
        
        "Derivative Works" shall mean any work, whether in Source or Object
        form, that is based on (or derived from) the Work and for which the
        editorial revisions, annotations, elaborations, or other modifications
        represent, as a whole, an original work of authorship. For the purposes
        of this License, Derivative Works shall not include works that remain
        separable from, or merely link (or bind by name) to the interfaces of,
        the Work and Derivative Works thereof.
        
        "Contribution" shall mean any work of authorship, including
        the original version of the Work and any modifications or additions
        to that Work or Derivative Works thereof, that is intentionally
        submitted to Licensor for inclusion in the Work by the copyright owner
        or by an individual or Legal Entity authorized to submit on behalf of
        the copyright owner. For the purposes of this definition, "submitted"
        means any form of electronic, verbal, or written communication sent
        to the Licensor or its representatives, including but not limited to
        communication on electronic mailing lists, source code control systems,
        and issue tracking systems that are managed by, or on behalf of, the
        Licensor for the purpose of discussing and improving the Work, but
        excluding communication that is conspicuously marked or otherwise
        designated in writing by the copyright owner as "Not a Contribution."
        
        "Contributor" shall mean Licensor and any individual or Legal Entity
        on behalf of whom a Contribution has been received by Licensor and
        subsequently incorporated within the Work.
        
        2. Grant of Copyright License. Subject to the terms and conditions of
        this License, each Contributor hereby grants to You a perpetual,
        worldwide, non-exclusive, no-charge, royalty-free, irrevocable
        copyright license to reproduce, prepare Derivative Works of,
        publicly display, publicly perform, sublicense, and distribute the
        Work and such Derivative Works in Source or Object form.
        
        3. Grant of Patent License. Subject to the terms and conditions of
        this License, each Contributor hereby grants to You a perpetual,
        worldwide, non-exclusive, no-charge, royalty-free, irrevocable
        (except as stated in this section) patent license to make, have made,
        use, offer to sell, sell, import, and otherwise transfer the Work,
        where such license applies only to those patent claims licensable
        by such Contributor that are necessarily infringed by their
        Contribution(s) alone or by combination of their Contribution(s)
        with the Work to which such Contribution(s) was submitted. If You
        institute patent litigation against any entity (including a
        cross-claim or counterclaim in a lawsuit) alleging that the Work
        or a Contribution incorporated within the Work constitutes direct
        or contributory patent infringement, then any patent licenses
        granted to You under this License for that Work shall terminate
        as of the date such litigation is filed.
        
        4. Redistribution. You may reproduce and distribute copies of the
        Work or Derivative Works thereof in any medium, with or without
        modifications, and in Source or Object form, provided that You
        meet the following conditions:
        
        (a) You must give any other recipients of the Work or
        Derivative Works a copy of this License; and
        
        (b) You must cause any modified files to carry prominent notices
        stating that You changed the files; and
        
        (c) You must retain, in the Source form of any Derivative Works
        that You distribute, all copyright, patent, trademark, and
        attribution notices from the Source form of the Work,
        excluding those notices that do not pertain to any part of
        the Derivative Works; and
        
        (d) If the Work includes a "NOTICE" text file as part of its
        distribution, then any Derivative Works that You distribute must
        include a readable copy of the attribution notices contained
        within such NOTICE file, excluding those notices that do not
        pertain to any part of the Derivative Works, in at least one
        of the following places: within a NOTICE text file distributed
        as part of the Derivative Works; within the Source form or
        documentation, if provided along with the Derivative Works; or,
        within a display generated by the Derivative Works, if and
        wherever such third-party notices normally appear. The contents
        of the NOTICE file are for informational purposes only and
        do not modify the License. You may add Your own attribution
        notices within Derivative Works that You distribute, alongside
        or as an addendum to the NOTICE text from the Work, provided
        that such additional attribution notices cannot be construed
        as modifying the License.
        
        You may add Your own copyright statement to Your modifications and
        may provide additional or different license terms and conditions
        for use, reproduction, or distribution of Your modifications, or
        for any such Derivative Works as a whole, provided Your use,
        reproduction, and distribution of the Work otherwise complies with
        the conditions stated in this License.
        
        5. Submission of Contributions. Unless You explicitly state otherwise,
        any Contribution intentionally submitted for inclusion in the Work
        by You to the Licensor shall be under the terms and conditions of
        this License, without any additional terms or conditions.
        Notwithstanding the above, nothing herein shall supersede or modify
        the terms of any separate license agreement you may have executed
        with Licensor regarding such Contributions.
        
        6. Trademarks. This License does not grant permission to use the trade
        names, trademarks, service marks, or product names of the Licensor,
        except as required for reasonable and customary use in describing the
        origin of the Work and reproducing the content of the NOTICE file.
        
        7. Disclaimer of Warranty. Unless required by applicable law or
        agreed to in writing, Licensor provides the Work (and each
        Contributor provides its Contributions) on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
        implied, including, without limitation, any warranties or conditions
        of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
        PARTICULAR PURPOSE. You are solely responsible for determining the
        appropriateness of using or redistributing the Work and assume any
        risks associated with Your exercise of permissions under this License.
        
        8. Limitation of Liability. In no event and under no legal theory,
        whether in tort (including negligence), contract, or otherwise,
        unless required by applicable law (such as deliberate and grossly
        negligent acts) or agreed to in writing, shall any Contributor be
        liable to You for damages, including any direct, indirect, special,
        incidental, or consequential damages of any character arising as a
        result of this License or out of the use or inability to use the
        Work (including but not limited to damages for loss of goodwill,
        work stoppage, computer failure or malfunction, or any and all
        other commercial damages or losses), even if such Contributor
        has been advised of the possibility of such damages.
        
        9. Accepting Warranty or Additional Liability. While redistributing
        the Work or Derivative Works thereof, You may choose to offer,
        and charge a fee for, acceptance of support, warranty, indemnity,
        or other liability obligations and/or rights consistent with this
        License. However, in accepting such obligations, You may act only
        on Your own behalf and on Your sole responsibility, not on behalf
        of any other Contributor, and only if You agree to indemnify,
        defend, and hold each Contributor harmless for any liability
        incurred by, or claims asserted against, such Contributor by reason
        of your accepting any such warranty or additional liability.
        
        END OF TERMS AND CONDITIONS
License-File: LICENSE
Keywords: aws,logging,ocsf,security,security-lake
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security
Classifier: Topic :: System :: Logging
Requires-Python: >=3.10
Requires-Dist: boto3>=1.26.0
Requires-Dist: botocore>=1.29.0
Provides-Extra: dev
Requires-Dist: black>=23.0; extra == 'dev'
Requires-Dist: boto3-stubs[iam,securitylake,sts]>=1.26.0; extra == 'dev'
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Description-Content-Type: text/markdown

# Security Lake Tools

[![CI](https://github.com/tenzir/security-lake-tools/actions/workflows/test.yml/badge.svg)](https://github.com/tenzir/security-lake-tools/actions/workflows/test.yml)
[![PyPI version](https://badge.fury.io/py/security-lake-tools.svg)](https://badge.fury.io/py/security-lake-tools)
[![Python versions](https://img.shields.io/pypi/pyversions/security-lake-tools.svg)](https://pypi.org/project/security-lake-tools/)
[![License](https://img.shields.io/pypi/l/security-lake-tools.svg)](https://github.com/tenzir/security-lake-tools/blob/main/LICENSE)

Tools for managing AWS Security Lake custom sources with OCSF (Open Cybersecurity Schema Framework) support.

## Features

- ✨ Create Security Lake custom sources for all OCSF event classes
- 🔧 Automatic IAM role creation for AWS Glue crawlers
- 📋 Built-in OCSF event class mapping
- 🔍 Detailed error messages and troubleshooting guidance
- 🚀 Simple command-line interface

## Installation

### Using uvx (Recommended)

The easiest way to use this tool is with [uvx](https://github.com/astral-sh/uv), which runs the tool in an isolated environment:

```bash
# Run directly without installation
uvx --from security-lake-tools security-lake-create-source --help

# Or with a shorter alias
alias sl-create='uvx --from security-lake-tools security-lake-create-source'
sl-create 1001 --external-id your-external-id
```

### Traditional Installation

Using pip:
```bash
pip install security-lake-tools
```

Using [uv](https://github.com/astral-sh/uv):
```bash
uv pip install security-lake-tools
```

## Quick Start

### Create a custom source

```bash
# Using uvx (no installation needed)
uvx --from security-lake-tools security-lake-create-source 1001 \
  --external-id your-external-id \
  --region us-east-1

# Or if installed traditionally
security-lake-create-source 1001 \
  --external-id your-external-id \
  --region us-east-1

# With explicit configuration
uvx --from security-lake-tools security-lake-create-source 1001 \
  --external-id your-external-id \
  --region us-east-1 \
  --account-id 123456789012 \
  --profile production
```

### List available OCSF event classes

```bash
# Using uvx
uvx --from security-lake-tools security-lake-create-source --list

# Or if installed
security-lake-create-source --list
```

## Detailed Usage

### Prerequisites

1. **AWS Credentials**: Configure AWS credentials using one of:
   - `aws configure`
   - Environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)
   - IAM role (if running on EC2)

2. **Security Lake**: Ensure Security Lake is enabled in your target region

3. **IAM Permissions**: You need permissions to:
   - Create IAM roles and policies
   - Create Security Lake custom sources
   - Create and manage Glue crawlers

### Command-Line Options

```bash
security-lake-create-source [OPTIONS] CLASS_UID

Arguments:
  CLASS_UID          OCSF class UID (e.g., 1001 for File System Activity)

Options:
  --region           AWS region (default: us-east-1)
  --account-id       AWS account ID (default: auto-detected)
  --external-id      External ID for trust relationship (required)
  --glue-role-arn    ARN of existing Glue service role
  --profile          AWS profile to use
  --no-create-role   Don't auto-create Glue role if missing
  --skip-role-check  Skip Glue role verification
  --list             List all available OCSF class UIDs
  --help             Show help message
```

### OCSF Event Classes

The tool supports all standard OCSF event classes:

#### System Activity (1xxx)
- 1001: File System Activity
- 1002: Kernel Extension Activity
- 1003: Kernel Activity
- 1004: Memory Activity
- 1005: Module Activity
- 1006: Scheduled Job Activity
- 1007: Process Activity
- 1008: Event Log Activity
- 1009: Script Activity

#### Findings (2xxx)
- 2001: Security Finding
- 2002: Vulnerability Finding
- 2003: Compliance Finding
- 2004: Detection Finding
- 2005: Incident Finding
- 2006: Data Security Finding
- 2007: Application Security Posture Finding

[See full list with `--list` option]

### IAM Role Management

By default, the tool automatically creates a Glue service role with:
- Trust relationship with `glue.amazonaws.com`
- AWS managed policy `AWSGlueServiceRole`
- Custom S3 policy for Security Lake buckets
- Lake Formation permissions

To use an existing role:
```bash
security-lake-create-source 1001 \
  --external-id your-external-id \
  --glue-role-arn arn:aws:iam::123456789012:role/MyExistingGlueRole
```

To prevent automatic role creation:
```bash
security-lake-create-source 1001 \
  --external-id your-external-id \
  --no-create-role
```

## What Gets Created

For each custom source, Security Lake creates:

1. **Provider Role**: `AmazonSecurityLake-Provider-{source-name}-{region}`
   - Allows the specified account to write logs to Security Lake

2. **S3 Location**: `s3://aws-security-data-lake-{region}-{id}/ext/{source-name}/`
   - Where your OCSF-formatted logs should be written

3. **Glue Resources**:
   - Crawler: Discovers and catalogs your data
   - Database: Stores metadata
   - Table: Defines the schema

## Troubleshooting

### Common Issues

1. **"The Glue role does not exist"**
   - Let the tool create it automatically (default behavior)
   - Or create manually with proper permissions
   - Or specify existing role with `--glue-role-arn`

2. **"Source already exists"**
   - Delete the existing source first
   - Or use a different class UID

3. **"Security Lake not enabled"**
   - Enable Security Lake in the AWS Console
   - Ensure you're using the correct region

4. **"Invalid principal" error**
   - Ensure the account ID is correct
   - Check that the external ID matches your configuration

### Debug Mode

For more detailed output, set the `AWS_DEBUG` environment variable:
```bash
AWS_DEBUG=1 security-lake-create-source 1001 --external-id test
```

## Development

### Setup

```bash
# Clone the repository
git clone https://github.com/yourusername/security-lake-tools
cd security-lake-tools

# Install with development dependencies using uv
uv pip install -e ".[dev]"
```

### Running Tests

```bash
# Run tests
uv run pytest

# With coverage
uv run pytest --cov=security_lake_tools
```

### Code Quality

```bash
# Format code
uv run black src tests

# Lint
uv run ruff check src tests

# Type checking
uv run mypy src
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## License

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- AWS Security Lake team for the service
- OCSF community for the schema framework
- Contributors and users of this tool