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

Refactor Docker setup, follow best-practices in containerization and make caldera easier to deploy #3114

Merged
merged 4 commits into from
Mar 25, 2025

Conversation

daw1012345
Copy link
Contributor

@daw1012345 daw1012345 commented Dec 26, 2024

Description

This project is currently quite difficult to get working. This is one of (at least) three pull requests intended to make caldera simpler to deploy or get running locally. Docker is a great tool for this, and should be the easiest and quickest deployment option.

Unfortunately, the current Dockerfile doesn't even build (due to an outdated version of Ubuntu).
This PR:

  • Updates the Dockerfile to use a staged build to compile the UI and copies it over to the final container. This avoids the dance of installing node and npm, building the UI, then removing node and npm.
  • Ensures that previous builds of caldera do not pollute the build within the container. For example, if caldera was ever compiled outside of Docker (especially the UI), it will not be recompiled in the container. This can cause a large headache, for example when the Docker build does not re-build the UI when the VITE_BASE_URL was changed.
  • Containers should contain all basic requirements for all of the functionality to work. For example - if a container is compiled without emu support and then published to DockerHub, a user will not be able to easily get all the dependencies into the container (without modifying the Dockerfile and building it themselves). This PR ensures this is the case.
  • The emu and atomic plugins depend on large submodules to work, but are capable of fetching them when they are enabled. This PR introduces two flavours of images - slim and full. The full (default) flavor contains said submodules to allow the container to work in environments without an internet connection, while the slim flavour disables the plugins and only fetches the submodules when they are enabled.
  • Modify the workflow to build and push both slim and full images to GHCR (tagged appropriately).
  • Adds a dependency on setuptools to work with recent versions of Python3
  • Makes Docker the recommended deployment option in the README
  • Every deployment of caldera using any of the currently provided Docker containers has the same password as it is generated during build-time.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Repeated build tests of both flavors of caldera (full + slim). The resulting containers appear to work when interacted with.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • [NOT RELEVANT] I have added tests that prove my fix is effective or that my feature works

@rfulwell
Copy link
Contributor

rfulwell commented Dec 27, 2024

These changes are super interesting and I look forward to going through them in detail! 🚀

Unfortunately, the current Dockerfile doesn't even build (due to an outdated version of Ubuntu).

In the meantime, here's the minimal fix for the Docker build which was approved and just waiting on a merge:
#3099 @daw1012345

@rfulwell
Copy link
Contributor

Docker is a great tool for [deployment], and should be the easiest and quickest deployment option.

💯

Thank you for tackling these changes! I fully agree that this project will be much more useful when Docker deployment is trivial. 👍

@daw1012345
Copy link
Contributor Author

Thanks @rfulwell. I made a few additional change to the Docker setup, I was wondering if you could test it yourself as well to make sure everything works? I am by no means a caldera power user and would like to make sure these changes don't break anything.

@daw1012345
Copy link
Contributor Author

And thank you for the original PR fixing the outdated Ubuntu version in the Dockerfile, hope that gets merged quickly as well.

@daw1012345 daw1012345 force-pushed the refactor-docker branch 2 times, most recently from ac27f4a to 223a63b Compare January 5, 2025 19:43
@elegantmoose elegantmoose requested a review from clenk January 9, 2025 18:41
@elegantmoose
Copy link
Contributor

On our queue.

@endiz
Copy link
Contributor

endiz commented Mar 12, 2025

While I don't use docker for this project, I think quite a lot of people do to quickly get started. This PR would be a great service to the community.

@elegantmoose elegantmoose requested review from uruwhy and removed request for clenk March 12, 2025 15:25
@elegantmoose
Copy link
Contributor

@endiz Yep, @uruwhy is gonna look at this one once he has a minute.

Copy link
Contributor

@uruwhy uruwhy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor merge conflicts and a couple suggestions to get rid of the warning messages, and should be good to go

Follow best-practices and make caldera easier to use
Copy link
Contributor

@uruwhy uruwhy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final piece since it looks like there's a conflict between the setuptools in requirements.txt and in tox.ini. Can you remove the setuptools from tox.ini since we're now specifying it in requirements.txt? That should allow our workflows to run properly, and once those pass we can move this forward

requirements.txt is being used instead
@daw1012345 daw1012345 requested a review from uruwhy March 18, 2025 15:17
uruwhy
uruwhy previously approved these changes Mar 18, 2025
@elegantmoose
Copy link
Contributor

@uruwhy approved and this is now on queue. Will look at asap.

@elegantmoose
Copy link
Contributor

elegantmoose commented Mar 24, 2025

@daw1012345 @endiz @rfulwell - want to get your thoughts:

UPDATE: Belay below comments. Github error, was not running right dockerfile.

  1. Any issues with using Ubuntu 24.04 instead of 23.04? (since LTS)
  2. By default, this creates the user credentials and puts them in the container at caldera/conf/local.yaml; i.e. a user will need to do a docker exec -it <container> /bin/bash to get in the container and then view the user credentials to use. Is this okay (i.e. not too annoying)? Or would we want to like print out to terminal the user credentials so easy to get/use.

@daw1012345
Copy link
Contributor Author

@elegantmoose I had no issues using a newer version of Debian>

Regarding your second point: it prints out the credentials on first run already (at the very top).

@elegantmoose
Copy link
Contributor

I dont follow. You mean like where the config file is?

@daw1012345
Copy link
Contributor Author

I dont follow. You mean like where the config file is?

No, it prints out the generated credentials.

For example:
image

(This is a sample container, the random credentials are not sensitive)

@elegantmoose
Copy link
Contributor

elegantmoose commented Mar 24, 2025

weird, not seeing that at all. Let me investigate.

--> UPDATE github had a hiccup. (was telling me was on your branch, but none of the new code was there)

@elegantmoose
Copy link
Contributor

@daw1012345 Alright cool, working clean now.

One request, could be we put like ENV COLUMNS=120 in the Dockerfile so that the Caldera log output is not too narrow?

Impetus: When I went to copy the credential password from the log output, it breaks over multiple lines and has large gap spaces, so I had to paste into notepad, remove newlines and return then re copy, then paste into Caldera.

elegantmoose
elegantmoose previously approved these changes Mar 24, 2025
@daw1012345
Copy link
Contributor Author

@elegantmoose The better approach would be to encourage the users to run it in proper TTY mode (-it flag).

@daw1012345 daw1012345 dismissed stale reviews from elegantmoose and uruwhy via 5e095fd March 24, 2025 20:47
@elegantmoose elegantmoose merged commit 45f71a3 into mitre:master Mar 25, 2025
1 of 5 checks passed
@elegantmoose
Copy link
Contributor

TY @daw1012345 . 👏

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.

6 participants