Isn't it common for rental servers to use environmental variables?

Asked 2 years ago, Updated 2 years ago, 54 views

Question 1
Isn't it common for rental servers to use environmental variables?
If I want to use environment variables, would it be more secure to use clouds such as VPS and AWS?

Survey 1
When I contacted a rental server's support, they replied that it was not supported.

Survey 2
I searched by words such as "Rental Server Environment Variable Settings" and found
This time, I came to this question because there was no official explanation of how to set environment variables on the rental server and there were few explanatory articles.

What do you want to do
I would like to dynamically type multiple pins into the map using Google's Places API.
We are currently considering where to save the API key to use.

If there is any missing information, I will supplement it as much as possible.
Thank you for your cooperation.

Also, if you use environment variables on the rental server,
I would appreciate it if you could tell me how to do it if you are using it.

php linux

2022-09-29 21:56

2 Answers

The so-called rental server (a type of web hosting service, also known as a shared server) runs multiple independent user sites on a single web server app (Apache HTTP Server or nginx).Each user's site is not visible to each other, and the execution environment has been dropped into the user's permissions or isolated by chroot with technology such as suEXEC, but it is originally run from a single web server app.

Normally, when it comes to passing environment variables, it is passed to the web server application by setting Environment in the systemd unit file.However, there is only one web server app, so if you set the environment variable for one user, it will be shared with all users.This is a kind of security hole for a rental server that provides an independent environment for each user.Also, if the environment variables you want to set overlap, you will have a dispute over which one to prioritize.

Well, what we can't do is we can't do that.For Apache HTTP Server, SetEnv directives.This means that you can set any environment variable, not just for the entire server, but for each host or directory.The problem I mentioned earlier was that setting the environment variable in the web server application makes it common to all users.However, with this, I think I can set any environment variable for each site (virtual host) or directory.However, there is still a problem.These are Apache HTTP Server settings, but it is difficult for users to change them, and it is also a problem that they need to restart the service every time they make changes.

Don't give up yet.Surprisingly, SetEnv can also be used in .htaccess, and .htaccess can be configured for each user or, more precisely, for each directory to publish.If you put .htaccess in the directory where the program is located and use SetEnv, you can use any environment variable.This gives users the freedom to configure themselves in their own area and eliminates the need for trouble such as restarting services.The only problem is that .htaccess may limit the available directives.(.htaccess can be restricted by Apache HTTP Server configuration)

The introduction has become longer.Environment variables are acceptable for rental servers that meet the following requirements:

  • .htaccess is available.
  • .htaccess allows you to use the SetEnv directive.

I don't know if this can be used on Xserver or other rental server.Xserver appears to be able to use .htaccess, but there was no information on which directives could be used.The only way to do this is to actually set it up and try it out.

Now that we've come this far, there's one thing to be careful about.Why should API keys be set to environment variables?If the entire program is managed by a repository such as GitHub, the API key in the code will also go up to the repository.If it was a public repository, the API key would be published around the world wide.Published API keys are abused in no time.If that happens, you will end up in a situation where you can't be fashionable with a multi-million yen fee bill for your account BAN and some services.

I just wrote that .htaccess should be using SetEnv.wait a minute。Isn't that .htaccess something that anyone can see?Access to .htaccess is limited on most servers, but not always.You may need to set it so that you cannot access it properly.The other thing is that .htaccess is placed in the same place as the program, so if you manage it in the repository I mentioned earlier, you may want to manage it together.In such cases, embedding the API key in .htaccess is not a good idea.

What I want to say is, don't stop thinking, "API keys are safe in environment variables." An environment variable can be dangerous if the location of the environment variable is disclosed.What's important is to never reveal where the API key is written.In general, if you set it with the environment variable of the process itself, it's a different place from the source tree, so it's often just that it's safe.It means that it is sufficient if it does not appear on the source tree, such as writing to a configuration file that is excluded from the repository or saving it to a DB.


2022-09-29 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.