Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9f95a4e
First cut at creating this Lambda function
jsf9k Aug 29, 2024
cfab690
Ensure that expiration_days is nonzero
jsf9k Aug 30, 2024
24997b9
Correct the way I was using boto3 paginators
jsf9k Aug 30, 2024
025efba
Ignore access keys that are already inactive
jsf9k Aug 30, 2024
47253b9
Handle the case where a user's console access was created recently
jsf9k Aug 30, 2024
0834ed5
Handle the case where a user's access key was created recently
jsf9k Aug 30, 2024
f9d6bea
Update Pipfiles (and lock files) for this project
jsf9k Aug 30, 2024
8142ee4
Update Docker composition to match the needs of this project
jsf9k Aug 30, 2024
f470e94
Correctly use boto3 IAM client exception class
jsf9k Aug 30, 2024
8c9da65
Make now a timezone-aware datetime object
jsf9k Aug 30, 2024
a3b54ec
Remove boto3 from the Pipfiles
jsf9k Aug 30, 2024
1236fea
Correctly extract the last used date from the get_access_key_last_use…
jsf9k Aug 30, 2024
deaedec
Correctly handle the case where the user has never used his or her co…
jsf9k Aug 30, 2024
d17992f
Add a debug message for the case where an access key is already inactive
jsf9k Aug 30, 2024
bba9e3b
Word-wrap paragraph to get rid of linting error
jsf9k Aug 30, 2024
aabbede
Correct reference to repo that does not exist
jsf9k Aug 30, 2024
1a2521a
Uncomment code that actually does the disabling
jsf9k Aug 30, 2024
96a0f51
Bump version from 0.0.2 to 1.0.0
jsf9k Aug 30, 2024
e3ecd04
Bump version from 1.0.0 to 1.0.0-rc.1
jsf9k Aug 30, 2024
b6b80d6
Set author label in Dockerfile to the VM dev distro
jsf9k Aug 30, 2024
78a4470
Fix copy-and-paste errors
jsf9k Aug 30, 2024
469a51f
Uncomment Dependabot ignore lines
jsf9k Sep 2, 2024
1e4f918
Simplify timestamp logic
jsf9k Sep 3, 2024
df9e9e2
Add pydoc for task_disable() parameters
jsf9k Sep 3, 2024
15da8c6
Bump version from 1.0.0-rc.1 to 1.0.0-rc.2
jsf9k Sep 4, 2024
311f8b8
Add support for Python 3.10 and remove support for older versions of …
jsf9k Sep 4, 2024
0336155
Update workflow to only support Python 3.10 Lambda runtime
jsf9k Sep 4, 2024
28f2b82
Finalize version from 1.0.0-rc.2 to 1.0.0
jsf9k Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ updates:
- dependency-name: hashicorp/setup-terraform
- dependency-name: mxschmitt/action-tmate
- dependency-name: step-security/harden-runner
# # Managed by cisagov/disable-inactive-iam-users-lambda
# - dependency-name: actions/upload-artifact
# - dependency-name: github/codeql-action
# Managed by cisagov/skeleton-aws-lambda-python
- dependency-name: actions/upload-artifact
- dependency-name: github/codeql-action
package-ecosystem: github-actions
schedule:
interval: weekly
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ jobs:
matrix:
# Python runtime versions supported by AWS
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
steps:
- id: harden-runner
name: Harden the runner
Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ one.
## Pull requests ##

If you choose to [submit a pull
request](https://github.com/cisagov/disable-inactive-iam-users-lambda/pulls), you will
notice that our continuous integration (CI) system runs a fairly
extensive set of linters and syntax checkers. Your pull request may
fail these checks, and that's OK. If you want you can stop there and
wait for us to make the necessary corrections to ensure your code
passes the CI checks.
request](https://github.com/cisagov/disable-inactive-iam-users-lambda/pulls),
you will notice that our continuous integration (CI) system runs a
fairly extensive set of linters and syntax checkers. Your pull
request may fail these checks, and that's OK. If you want you can
stop there and wait for us to make the necessary corrections to ensure
your code passes the CI checks.

If you want to make the changes yourself, or if you want to become a
regular contributor, then you will want to set up
Expand Down
14 changes: 4 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ARG PY_VERSION=3.9
ARG PY_VERSION=3.10

FROM amazon/aws-lambda-python:$PY_VERSION as install-stage

# Declare it a second time so it's brought into this scope.
ARG PY_VERSION=3.9
ARG PY_VERSION=3.10

# Install the Python packages necessary to install the Lambda dependencies.
RUN python3 -m pip install --no-cache-dir \
Expand Down Expand Up @@ -31,17 +31,11 @@ FROM amazon/aws-lambda-python:$PY_VERSION as build-stage
# For a list of pre-defined annotation keys and value types see:
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
###
# github@cisa.dhs.gov is a very generic email distribution, and it is
# unlikely that anyone on that distribution is familiar with the
# particulars of your repository. It is therefore *strongly*
# suggested that you use an email address here that is specific to the
# person or group that maintains this repository; for example:
# LABEL org.opencontainers.image.authors="vm-fusion-dev-group@trio.dhs.gov"
LABEL org.opencontainers.image.authors="github@cisa.dhs.gov"
LABEL org.opencontainers.image.authors="vm-dev@gwe.cisa.dhs.gov"
LABEL org.opencontainers.image.vendor="Cybersecurity and Infrastructure Security Agency"

# Declare it a third time so it's brought into this scope.
ARG PY_VERSION=3.9
ARG PY_VERSION=3.10

# This must be present in the image to generate a deployment artifact.
ENV BUILD_PY_VERSION=$PY_VERSION
Expand Down
45 changes: 33 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

[![GitHub Build Status](https://github.com/cisagov/disable-inactive-iam-users-lambda/workflows/build/badge.svg)](https://github.com/cisagov/disable-inactive-iam-users-lambda/actions)

This is a generic skeleton project that can be used to quickly get a
new [cisagov](https://github.com/cisagov) GitHub
[AWS Lambda](https://aws.amazon.com/lambda/) project using the Python runtimes
started. This skeleton project contains [licensing information](LICENSE), as
well as [pre-commit hooks](https://pre-commit.com) and
[GitHub Actions](https://github.com/features/actions) configurations
appropriate for the major languages that we use.
This repository contains the code for an AWS Lambda function that
disables access for users who have not used said access sufficiently
recently.

## Building the base Lambda image ##

Expand Down Expand Up @@ -57,6 +53,13 @@ Once you are finished you can stop the detached container with the following com
docker compose down
```

To customize the name of the deployment file, you can override the
`BUILD_FILE_NAME` environment variable. For example:

```console
BUILD_FILE_NAME="disable_inactive_iam_users_lambda.zip" docker compose up build_deployment_package
```

## How to update Python dependencies ##

The Python dependencies are maintained using a [Pipenv](https://github.com/pypa/pipenv)
Expand All @@ -72,12 +75,30 @@ cd src/py3.9
pipenv lock
```

## New Repositories from a Skeleton ##
## Lambda inputs ##

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| expiration_days | A strictly positive integer denoting the number of days after which an IAM user's access is considered inactive if unused. | `number` | n/a | yes |

## Example Lambda input ##

The following is an example of the JSON input event that is expected by the
Lambda:

```json
{
"expiration_days": 45
}
```

## Deploying the Lambda ##

Please see our [Project Setup guide](https://github.com/cisagov/development-guide/tree/develop/project_setup)
for step-by-step instructions on how to start a new repository from
a skeleton. This will save you time and effort when configuring a
new repository!
The easiest way to deploy the Lambda and related resources is to use
the
[cisagov/disable-inactive-iam-users-tf-module](https://github.com/cisagov/disable-inactive-iam-users-tf-module)
repository. Refer to the documentation in that project for more
information.

## Contributing ##

Expand Down
9 changes: 1 addition & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
build: .
# This uses the value of the LAMBDA_TAG environment variable from
# the invoking environment but falls back to a default value.
image: cisagov/example_lambda:${LAMBDA_TAG:-latest}
image: cisagov/disable_inactive_iam_users_lambda:${LAMBDA_TAG:-latest}
entrypoint: /opt/build_artifact.sh
environment:
# This uses the value of the BUILD_FILE_NAME environment variable
Expand All @@ -15,10 +15,3 @@ services:
volumes:
- ./src/build_artifact.sh:/opt/build_artifact.sh
- .:/var/task/output
run_lambda_locally:
build: .
# This uses the value of the LAMBDA_TAG environment variable from
# the invoking environment but falls back to a default value.
image: cisagov/example_lambda:${LAMBDA_TAG:-latest}
ports:
- "9000:8080"
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
--requirement requirements-test.txt
# boto3 is not strictly required, but it can be useful for some local
# development testing activities, so we include it here as a
# convenience.
boto3
ipython
pipenv
semver
Loading