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

Have server.py automatically configure Magma .env when build flag set #2977

Merged
merged 3 commits into from May 15, 2024

Conversation

djlawren
Copy link
Contributor

Description

These changes modify server.py to set the contents of ./plugins/magma/.env when --build is used. The contents of Magma's VITE_CALDERA_URL environment variable is set to the host and port values set in the Caldera config.

A discrepancy between the URL used by Magma's router and the location of the Caldera server was noted as the cause of multiple issues: #2901, #2944, #2955

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

The change was manually verified by starting the Caldera server and noting through browser developer tools that the URL used for Caldera's requests changed when the Caldera config values changed, and the UI was rebuilt.

It should be noted that the inciting bug was still present the first time I tested. In testing, I used Caldera by running on a cloud VM and port forwarding to my local machine. The Caldera config's default host value of 0.0.0.0 caused the login screen to be impassable. In my specific situation, I had to change the config's host value to localhost or the VM's domain name to get past the login screen.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code

@elegantmoose
Copy link
Contributor

Addresses and closes #2901, #2944, #2955

@elegantmoose
Copy link
Contributor

Tested successfully on Ubuntu on Chrome and Firefox.

Copy link
Contributor

@clenk clenk left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @djlawren

@iknowjason
Copy link

iknowjason commented May 15, 2024

Looks like this PR broke my tool that uses Caldera with remote hosting on AWS EC2 instance. I'm getting a similar error that I received before on #2885

Was this tested on Caldera running on non-localhost or was it tested only on localhost?

@elegantmoose
@clenk

@djlawren
Copy link
Contributor Author

Looks like this PR broke my tool that uses Caldera with remote hosting on AWS EC2 instance. I'm getting a similar error that I received before on #2885

Was this tested on Caldera running on non-localhost or was it tested only on localhost?

@elegantmoose @clenk

I did test before merging with remote hosting on a cloud VM, with port 8888 on the remote VM forwarded to localhost. To make it work with these changes, I had to change the host value in the Caldera config located at ./conf/default.yaml or ./conf/local.yaml to either localhost or the domain name of the cloud VM.

The changes set the URL that the Vue UI sends requests to from the host and port values of the Caldera config. With the default values in the Caldera config the UI will attempt to send requests to 0.0.0.0:8888. The Caldera config then needs to be changed to make sure it's sending requests to the correct place. Before these changes, the request URL was hardcoded to localhost:8888 unless a user manually set the .env in Magma.

We added a corresponding paragraph to the documentation to note the required remediation: https://caldera.readthedocs.io/en/latest/Server-Configuration.html#configuration-file

If this doesn't get towards addressing the issue for you, I'm happy to continue the discussion on fixing this problem in a way that supports remote hosting more generally.

@iknowjason
Copy link

Thanks for the details @djlawren . What about TLS support with this new PR? Did you test this out and what are users to do if they want to run magma with SSL support? I see what it is doing now and I"m able to build and run with http and port 8888. However, my system was built for SSL on port 8443. It looks here like your --build with server.py is hard-coding to build the VITE_CALDERA_URL in .env to be http instead of a configurable option. What if the user needs https in that .env to run? This would be the way and what I was doing before. I had a script that modified the VITE_URL to be https://<vps_dns>:8443.

Would be good to have an option to make this configurable for https or http just like host and port variables on local.yml.

https://github.com/mitre/caldera/blob/master/server.py#L155

Cc @prcabral

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.

None yet

4 participants