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

sops encryption/decryption with age key doesn't work for Python ini Files with [DEFAULT] section #1451

Open
TheRaspyDev opened this issue Mar 5, 2024 · 4 comments

Comments

@TheRaspyDev
Copy link

TheRaspyDev commented Mar 5, 2024

I have the following config.ini File for a Python project:

image

Running sops --encrypt config.ini > config__sops__.ini results in the following file:

image

Running sops --decrypt config__sops__.ini > config.ini results in the following file:

image

--> The [DEFAULT] section is stripped.

The [DEFAULT] section is very important for the Python configparser (https://docs.python.org/3/library/configparser.html#module-configparser). When it's missing, the configparser can't read the config file.

After decrypting and encrypting the config.ini, Python can't read the config.ini anymore.

When I rename the [DEFAULT] section name in config.ini File to [default] (or any other name), then sops works as expected (but Python won't work anymore).
It seems, that the [DEFAULT] section (with capital letters) is somehow reserved for sops???

A possible workaround for me is to define the "default" section in the Python code with setting the default_section property when initializing the configparser.

Please fix this issue.

Thanks in advance
TheRaspyDev

@felixfontein
Copy link
Contributor

It seems that the problem is that the INI library used by SOPS uses DEFAULT as the section name for entries outside a section (https://pkg.go.dev/gopkg.in/ini.v1?utm_source=godoc#pkg-variables). This is going to be tricky to fix, in particular without breaking backwards compatibility.

@felixfontein
Copy link
Contributor

(The name DEFAULT seems to be hard-coded in that library. :-( )

@TheRaspyDev
Copy link
Author

Thanks for the fast reply.

I always thought, that INI File is a "standard". But it seems that (at least) Python works different. In Python, a "default" section is mandatory (the .ini file has to start with a section header). Otherwise the configparser will fail.

The workaround (define a custom default_section) is fine for me at the moment:
config_parser = configparser.ConfigParser(default_section="common")

I'm looking forward whether a solution can be found for this bug.

@felixfontein
Copy link
Contributor

I always thought, that INI File is a "standard".

Unfortunately no, there are thousands of similar, but sometimes incompatible ways that applications deal with INI files...

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

No branches or pull requests

2 participants