Skip to content

Commit d43ed42

Browse files
committed
merge main
2 parents 0bb6a0a + 1ba4abc commit d43ed42

File tree

3 files changed

+73
-406
lines changed

3 files changed

+73
-406
lines changed

Dockerfile

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
FROM golang:1.21-alpine as builder
2-
3-
RUN apk add --no-cache git make curl openssl
4-
5-
# Configure Go
6-
ENV GOPATH=/go PATH=/go/bin:$PATH CGO_ENABLED=0 GO111MODULE=on
7-
RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin
8-
9-
WORKDIR /src
10-
11-
COPY go.mod .
12-
COPY go.sum .
13-
RUN go mod download
14-
15-
COPY . .
16-
17-
RUN set -x \
18-
&& make build \
19-
&& cp /src/dist/aws-nuke /usr/local/bin/
20-
21-
FROM alpine:latest
1+
# syntax=docker/dockerfile:1.10-labs
2+
FROM alpine:3.20.3 as base
223
RUN apk add --no-cache ca-certificates
4+
RUN adduser -D aws-nuke
235

24-
COPY --from=builder /usr/local/bin/* /usr/local/bin/
6+
FROM ghcr.io/acorn-io/images-mirror/golang:1.21 AS build
7+
COPY / /src
8+
WORKDIR /src
9+
ENV CGO_ENABLED=0
10+
RUN \
11+
--mount=type=cache,target=/go/pkg \
12+
--mount=type=cache,target=/root/.cache/go-build \
13+
go build -ldflags '-s -w -extldflags="-static"' -o bin/aws-nuke main.go
2514

26-
RUN adduser -D aws-nuke
15+
FROM base AS goreleaser
16+
ENTRYPOINT ["/usr/local/bin/aws-nuke"]
17+
COPY aws-nuke /usr/local/bin/aws-nuke
2718
USER aws-nuke
2819

20+
FROM base
2921
ENTRYPOINT ["/usr/local/bin/aws-nuke"]
22+
COPY --from=build --chmod=755 /src/bin/aws-nuke /usr/local/bin/aws-nuke
23+
RUN chmod +x /usr/local/bin/aws-nuke
24+
USER aws-nuke

README.md

Lines changed: 0 additions & 321 deletions
Original file line numberDiff line numberDiff line change
@@ -88,324 +88,3 @@ You can contribute to *aws-nuke* by forking this repository, making your changes
8888
this repository. If you are unsure how to solve a problem or have other questions about a contributions, please create
8989
a GitHub issue.
9090

91-
## Version 3
92-
93-
Version 3 is a rewrite of this tool using [libnuke](https://github.com/ekristen/libnuke) with a focus on improving a number of the outstanding things
94-
that I couldn't get done with the original project without separating out the core code into a library. See Goals
95-
below for more.
96-
97-
### Changes
98-
99-
- The root command will result in help now on v3, the primary nuke command moved to `nuke`. **Breaking**
100-
- CloudFormation Stacks now support a hold and wait for parent deletion process. **Quasi-Breaking**
101-
- Nested CloudFormation Stacks are now eligible for deletion and no longer omitted. **Quasi-Breaking**
102-
- The entire resource lister format has changed and requires a struct.
103-
- Context is passed throughout the entire library now, including the listing function and the removal function.
104-
- This is in preparation for supporting AWS SDK Go v2
105-
106-
### Goals
107-
108-
- Adding additional tests
109-
- Adding additional resources
110-
- Adding documentation for adding resources and using the tool
111-
- Consider adding DAG for dependencies between resource types and individual resources
112-
- This will improve the process of deleting resources that have dependencies on other resources and reduce
113-
errors and unnecessary API calls.
114-
115-
## Documentation
116-
117-
The project is built to have the documentation right alongside the code in the `docs/` directory leveraging
118-
[Material for Mkdocs](https://squidfunk.github.io/mkdocs-material/)
119-
120-
In the root of the project exists mkdocs.yml which drives the configuration for the documentation.
121-
122-
This README.md is currently copied to `docs/index.md` and the documentation is automatically published to the GitHub
123-
pages location for this repository using a GitHub Action workflow. It does not use the `gh-pages` branch.
124-
125-
126-
## Use Cases
127-
128-
- We are testing our [Terraform](https://www.terraform.io/) code with Jenkins. Sometimes a Terraform run fails during development and
129-
messes up the account. With *aws-nuke* we can simply clean up the failed account, so it can be reused for the next
130-
build.
131-
- Our platform developers have their own AWS Accounts where they can create their own Kubernetes clusters for testing
132-
purposes. With *aws-nuke* it is very easy to clean up these account at the end of the day and keep the costs low.
133-
134-
135-
### Feature Flags
136-
137-
There are some features, which are quite opinionated. To make those work for
138-
everyone, *aws-nuke* has flags to manually enable those features. These can be
139-
configured on the root-level of the config, like this:
140-
141-
```yaml
142-
---
143-
feature-flags:
144-
disable-deletion-protection:
145-
RDSInstance: true
146-
EC2Instance: true
147-
CloudformationStack: true
148-
force-delete-lightsail-addons: true
149-
```
150-
151-
### Filtering Resources
152-
153-
It is possible to filter this is important for not deleting the current user
154-
for example or for resources like S3 Buckets which have a globally shared
155-
namespace and might be hard to recreate. Currently the filtering is based on
156-
the resource identifier. The identifier will be printed as the first step of
157-
*aws-nuke* (eg `i-01b489457a60298dd` for an EC2 instance).
158-
159-
**Note: Even with filters you should not run aws-nuke on any AWS account, where
160-
you cannot afford to lose all resources. It is easy to make mistakes in the
161-
filter configuration. Also, since aws-nuke is in continous development, there
162-
is always a possibility to introduce new bugs, no matter how careful we review
163-
new code.**
164-
165-
The filters are part of the account-specific configuration and are grouped by
166-
resource types. This is an example of a config that deletes all resources but
167-
the `admin` user with its access permissions and two access keys:
168-
169-
```yaml
170-
---
171-
regions:
172-
- global
173-
- eu-west-1
174-
175-
account-blocklist:
176-
- 1234567890
177-
178-
accounts:
179-
0987654321:
180-
filters:
181-
IAMUser:
182-
- "admin"
183-
IAMUserPolicyAttachment:
184-
- "admin -> AdministratorAccess"
185-
IAMUserAccessKey:
186-
- "admin -> AKSDAFRETERSDF"
187-
- "admin -> AFGDSGRTEWSFEY"
188-
```
189-
190-
Any resource whose resource identifier exactly matches any of the filters in
191-
the list will be skipped. These will be marked as "filtered by config" on the
192-
*aws-nuke* run.
193-
194-
#### Filter Properties
195-
196-
Some resources support filtering via properties. When a resource support these
197-
properties, they will be listed in the output like in this example:
198-
199-
```log
200-
global - IAMUserPolicyAttachment - 'admin -> AdministratorAccess' - [RoleName: "admin", PolicyArn: "arn:aws:iam::aws:policy/AdministratorAccess", PolicyName: "AdministratorAccess"] - would remove
201-
```
202-
203-
To use properties, it is required to specify a object with `properties` and
204-
`value` instead of the plain string.
205-
206-
These types can be used to simplify the configuration. For example, it is
207-
possible to protect all access keys of a single user:
208-
209-
```yaml
210-
IAMUserAccessKey:
211-
- property: UserName
212-
value: "admin"
213-
```
214-
215-
#### Filter Types
216-
217-
There are also additional comparision types than an exact match:
218-
219-
- `exact` – The identifier must exactly match the given string. This is the default.
220-
- `contains` – The identifier must contain the given string.
221-
- `glob` – The identifier must match against the given [glob
222-
pattern](https://en.wikipedia.org/wiki/Glob_(programming)). This means the
223-
string might contains wildcards like `*` and `?`. Note that globbing is
224-
designed for file paths, so the wildcards do not match the directory
225-
separator (`/`). Details about the glob pattern can be found in the [library
226-
documentation](https://godoc.org/github.com/mb0/glob).
227-
- `regex` – The identifier must match against the given regular expression.
228-
Details about the syntax can be found in the [library
229-
documentation](https://golang.org/pkg/regexp/syntax/).
230-
- `dateOlderThan` - The identifier is parsed as a timestamp. After the offset is added
231-
to it (specified in the `value` field), the resulting timestamp must be AFTER the
232-
current time. Details on offset syntax can be found in the [library documentation](https://golang.org/pkg/time/#ParseDuration).
233-
Supported date formats are epoch time, `2006-01-02`, `2006/01/02`, `2006-01-02T15:04:05Z`,
234-
`2006-01-02T15:04:05.999999999Z07:00`, and `2006-01-02T15:04:05Z07:00`.
235-
236-
To use a non-default comparision type, it is required to specify an object with
237-
`type` and `value` instead of the plain string.
238-
239-
These types can be used to simplify the configuration. For example, it is
240-
possible to protect all access keys of a single user by using `glob`:
241-
242-
```yaml
243-
IAMUserAccessKey:
244-
- type: glob
245-
value: "admin -> *"
246-
```
247-
248-
#### Using Them Together
249-
250-
It is also possible to use Filter Properties and Filter Types together. For
251-
example to protect all Hosted Zone of a specific TLD:
252-
253-
```yaml
254-
Route53HostedZone:
255-
- property: Name
256-
type: glob
257-
value: "*.rebuy.cloud."
258-
```
259-
260-
#### Inverting Filter Results
261-
262-
Any filter result can be inverted by using `invert: true`, for example:
263-
264-
```yaml
265-
CloudFormationStack:
266-
- property: Name
267-
value: "foo"
268-
invert: true
269-
```
270-
271-
In this case *any* CloudFormationStack ***but*** the ones called "foo" will be
272-
filtered. Be aware that *aws-nuke* internally takes every resource and applies
273-
every filter on it. If a filter matches, it marks the node as filtered.
274-
275-
#### Filter Presets
276-
277-
It might be the case that some filters are the same across multiple accounts.
278-
This especially could happen, if provisioning tools like Terraform are used or
279-
if IAM resources follow the same pattern.
280-
281-
For this case *aws-nuke* supports presets of filters, that can applied on
282-
multiple accounts. A configuration could look like this:
283-
284-
```yaml
285-
---
286-
regions:
287-
- "global"
288-
- "eu-west-1"
289-
290-
account-blocklist:
291-
- 1234567890
292-
293-
accounts:
294-
555421337:
295-
presets:
296-
- "common"
297-
555133742:
298-
presets:
299-
- "common"
300-
- "terraform"
301-
555134237:
302-
presets:
303-
- "common"
304-
- "terraform"
305-
filters:
306-
EC2KeyPair:
307-
- "notebook"
308-
309-
presets:
310-
terraform:
311-
filters:
312-
S3Bucket:
313-
- type: glob
314-
value: "my-statebucket-*"
315-
DynamoDBTable:
316-
- "terraform-lock"
317-
common:
318-
filters:
319-
IAMRole:
320-
- "OrganizationAccountAccessRole"
321-
```
322-
323-
## Install
324-
325-
### For macOS
326-
`brew install aws-nuke`
327-
328-
### Use Released Binaries
329-
330-
The easiest way of installing it, is to download the latest
331-
[release](https://github.com/ekristen/aws-nuke/releases) from GitHub.
332-
333-
#### Example for Linux Intel/AMD
334-
335-
Download and extract
336-
`$ wget -c https://github.com/rebuy-de/aws-nuke/releases/download/v2.25.0/aws-nuke-v2.25.0-linux-amd64.tar.gz -O - | tar -xz -C $HOME/bin`
337-
338-
Run
339-
`$ aws-nuke-v2.25.0-linux-amd64`
340-
341-
### Compile from Source
342-
343-
To compile *aws-nuke* from source you need a working
344-
[Golang](https://golang.org/doc/install) development environment.
345-
346-
*aws-nuke* uses go modules and so the clone path should no matter.
347-
348-
The easiest way to compile is by using [goreleaser](https://goreleaser.io)
349-
350-
```bash
351-
goreleaser --rm-dist --snapshot --single-target
352-
```
353-
354-
**Note:** this will automatically build for your current architecture and place the result
355-
in the releases directory.
356-
357-
You may also use `make` to compile the binary, this was left over from before the fork.
358-
359-
Also you need to install [golint](https://github.com/golang/lint/) and [GNU
360-
Make](https://www.gnu.org/software/make/).
361-
362-
Then you just need to run `make build` to compile a binary into the project
363-
directory or `make install` go install *aws-nuke* into `$GOPATH/bin`. With
364-
`make xc` you can cross compile *aws-nuke* for other platforms.
365-
366-
### Docker
367-
368-
You can run *aws-nuke* with Docker by using a command like this:
369-
370-
```bash
371-
$ docker run \
372-
--rm -it \
373-
-v /full-path/to/nuke-config.yml:/home/aws-nuke/config.yml \
374-
-v /home/user/.aws:/home/aws-nuke/.aws \
375-
quay.io/rebuy/aws-nuke:v2.25.0 \
376-
--profile default \
377-
--config /home/aws-nuke/config.yml
378-
```
379-
380-
To make it work, you need to adjust the paths for the AWS config and the
381-
*aws-nuke* config.
382-
383-
Also you need to specify the correct AWS profile. Instead of mounting the AWS
384-
directory, you can use the `--access-key-id` and `--secret-access-key` flags.
385-
386-
Make sure you use the latest version in the image tag. Alternatiely you can use
387-
`main` for the latest development version, but be aware that this is more
388-
likely to break at any time.
389-
390-
## Testing
391-
392-
### Unit Tests
393-
394-
To unit test *aws-nuke*, some tests require [gomock](https://github.com/golang/mock) to run.
395-
This will run via `go generate ./...`, but is automatically run via `make test`.
396-
To run the unit tests:
397-
398-
```bash
399-
make test
400-
```
401-
402-
## Contact Channels
403-
404-
For now GitHub issues, may open a Slack or Discord if warranted.
405-
406-
## Contribute
407-
408-
You can contribute to *aws-nuke* by forking this repository, making your
409-
changes and creating a Pull Request against our repository. If you are unsure
410-
how to solve a problem or have other questions about a contributions, please
411-
create a GitHub issue.

0 commit comments

Comments
 (0)