-
Notifications
You must be signed in to change notification settings - Fork 641
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
[4.x]: Plugin license keys using environment variables are frequently overwritten #11830
Comments
I was able to reproduce this, but only if the environment variables were defined in PLUGIN_LICENSE_KEY_NAVIGATION= If the environment variables didn’t exist at all, or were set to a dummy key like Just fixed it for empty values, for the next Craft 3 and 4 releases – Craft will now leave those alone, and mark them as invalid. It won’t generate new license keys for you anymore; you will need to purchase the plugins from plugins.craftcms.com and create/update the license environment variables.
Worth mentioning that this isn’t really true since 3.6, which is actually tied to the reason your plugins were getting license keys automatically. Since 3.6, Craft will be assigned license keys for all installed plugins, with a “trial” status. You can commit chose license keys to your project config, and they can be purchased from production later on. The license key statuses will be changed to “active” without affecting the license key. So there’s no need to make any project config changes at that time. So the only reason to use environment variables is if you want to keep the keys out of your project config (which is still perfectly valid). |
@brandonkelly Thank you! 🚀 Yes, having the environment variables set to an empty value is normal in our workflow. We have a starter project that uses environment variables for license keys, so whenever we set up a new project or a new team member sets up their local development environment for an existing one, the environment variables are empty, since they don't have a license yet. This was causing the
Just to be clear; we usually purchase the licenses when a project goes live, and work with trial licenses during development. If Craft won't generate trial license keys anymore, will we have any problems? Or can we just continue to use our development environments without license keys for the commercial plugins?
This wasn't working for us before we switched to environment variables, though now I'm not sure what the exact problem was. Might've been related to our starter project which always included the same license key, so that license key was already bound to a different domain. Anyway, I'll test this once the next version with this fix is released! |
Yeah that’s obvious in hindsight. Took me a while to get there because I thought you were saying you used
The original idea was to just have Craft treat empty values the same as invalid values (e.g. But that would cause Craft to show license nag alerts at the top of every control panel page, which would get pretty annoying. And as I said it would force you to purchase a license at plugins.craftcms.com when you go live, which is at best a lateral move compared to your prior workflow. On second thought I realized I could approach this a little differently: continue to treat empty environment variable values as if there’s no license key at all, so Craft requests that a trial license key be assigned (like before), but then at the point where we save out the new license key, we can just update the Just made that change for the next release (22165ac). |
Craft 3.7.53 and 4.2.3 are both out with that change now. |
@brandonkelly Sorry for the confusion! I meant this as a placeholder for a valid license, should've been more explicit.
That's exactly what I was hoping for! Thanks a bunch, this will make our dev setup much simpler! 🚀 |
Thanks @brandonkelly and @MoritzLost! |
Description
We're using environment variables for the license keys for Craft and plugin licenses, so we can buy licenses and add them to the production environment directly. This is a much simpler process for sites going live, because it means we can buy the licenses and use them on a site without a developer having to include the new license key in the project config in a development environment and create a pull request. Besides that, it's good practice in general to keep secrets like license keys out of version control.
Our environment looks a little like this:
The license keys are defined using those environment variables in the
config/project/project.yaml
:While Craft does support this usage, it causes problems when setting up a new project or creating a new development environment. If you don't have a license key yet, Craft will create a new license key and write it to the project config, overwriting the environment variable setting. This happens as soon as you use
php craft install/craft
, or view the plugin settings in the backend, or do anything at all really. The problem is that there's no way to request a new license key without Craft writing it to the project config – for development purposes, at this point we haven't bought the plugin licenses yet, since the project is still in development. Besides that, we use trial license keys for development and only use the real license keys for the live site.Anyway, this means the steps to install a project using environment variables for license keys are pretty unintuitive and error-prone:
php craft install/craft
, during the installation (or at the latest once you visit the backend) Craft will create a new license key and write it to theproject.yaml
..env
file.git restore config/project/project.yaml
to restore the previousproject.yaml
andphp craft project-config/apply
to force Craft to use the environment variable again.Steps to reproduce
PLUGIN_LICENSE_KEY_NAVIGATION
) and set it to the current license key used for the plugin.$
-sign in front in the field for the plugin's license key ($PLUGIN_LICENSE_KEY_NAVIGATION
).config/project/project.yaml
, replacing the hardcoded license key..env
and reload the Settings -> Plugins page.config/project/project.yaml
, forcibly overwriting the environment variable setting.Expected behavior
There should be a way to create development license keys without having them written to the
project.yaml
which leads to having to awkwardly reset & apply the file every time. I see two possible solutions:.env
file instead of theproject.yaml
. The commandssetup/app-id
andsetup/security-key
already do this, so it's not unprecedented.project.yaml
. This could be a Console Command or a function on id.craftcms.com. This would allow us to create license keys for a new dev environment and set it in the.env
before the installation.Actual behavior
There's no way to create new development license keys for plugins without Craft writing them to the
project.yaml
, which is not great if you're using environment variables to define plugin keys.Craft CMS version
4.2.2
PHP version
8.1
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
No response
The text was updated successfully, but these errors were encountered: