mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-07-29 15:55:47 -05:00
Move csrgen templates into ipaclient package
csrgen broke packaging of ipaclient for PyPI. All csrgen related resources are now package data of ipaclient package. Package data is accessed with Jinja's PackageLoader() or through pkg_resources. https://pagure.io/freeipa/issue/6714 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Ben Lipton <blipton@redhat.com> Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
committed by
David Kupka
parent
f8d7e37a09
commit
80be181629
+15
-6
@@ -8,6 +8,8 @@ import os.path
|
||||
import pipes
|
||||
import traceback
|
||||
|
||||
import pkg_resources
|
||||
|
||||
import jinja2
|
||||
import jinja2.ext
|
||||
import jinja2.sandbox
|
||||
@@ -15,7 +17,6 @@ import six
|
||||
|
||||
from ipalib import errors
|
||||
from ipalib.text import _
|
||||
from ipaplatform.paths import paths
|
||||
from ipapython.ipa_log_manager import log_mgr
|
||||
|
||||
if six.PY3:
|
||||
@@ -72,10 +73,14 @@ class Formatter(object):
|
||||
"""
|
||||
base_template_name = None
|
||||
|
||||
def __init__(self, csr_data_dir=paths.CSR_DATA_DIR):
|
||||
def __init__(self, csr_data_dir=None):
|
||||
if csr_data_dir is not None:
|
||||
loader = jinja2.FileSystemLoader(
|
||||
os.path.join(csr_data_dir, 'templates'))
|
||||
else:
|
||||
loader = jinja2.PackageLoader('ipaclient', 'csrgen/templates')
|
||||
self.jinja2 = jinja2.sandbox.SandboxedEnvironment(
|
||||
loader=jinja2.FileSystemLoader(
|
||||
os.path.join(csr_data_dir, 'templates')),
|
||||
loader=loader,
|
||||
extensions=[jinja2.ext.ExprStmtExtension, IPAExtension],
|
||||
keep_trailing_newline=True, undefined=IndexableUndefined)
|
||||
|
||||
@@ -277,9 +282,13 @@ class RuleProvider(object):
|
||||
|
||||
|
||||
class FileRuleProvider(RuleProvider):
|
||||
def __init__(self, csr_data_dir=paths.CSR_DATA_DIR):
|
||||
def __init__(self, csr_data_dir=None):
|
||||
self.rules = {}
|
||||
self.csr_data_dir = csr_data_dir
|
||||
if csr_data_dir is None:
|
||||
self.csr_data_dir = pkg_resources.resource_filename(
|
||||
'ipaclient', 'csrgen')
|
||||
else:
|
||||
self.csr_data_dir = csr_data_dir
|
||||
|
||||
def _rule(self, rule_name, helper):
|
||||
if (rule_name, helper) not in self.rules:
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{
|
||||
"syntax": "syntaxSubject",
|
||||
"data": [
|
||||
"dataHostCN",
|
||||
"dataSubjectBase"
|
||||
]
|
||||
},
|
||||
{
|
||||
"syntax": "syntaxSAN",
|
||||
"data": [
|
||||
"dataDNS"
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{
|
||||
"syntax": "syntaxSubject",
|
||||
"data": [
|
||||
"dataUsernameCN",
|
||||
"dataSubjectBase"
|
||||
]
|
||||
},
|
||||
{
|
||||
"syntax": "syntaxSAN",
|
||||
"data": [
|
||||
"dataEmail"
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"helper": "openssl",
|
||||
"template": "DNS = {{subject.krbprincipalname.0.partition('/')[2].partition('@')[0]}}"
|
||||
},
|
||||
{
|
||||
"helper": "certutil",
|
||||
"template": "dns:{{subject.krbprincipalname.0.partition('/')[2].partition('@')[0]|quote}}"
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"data_source": "subject.krbprincipalname.0.partition('/')[2].partition('@')[0]"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"helper": "openssl",
|
||||
"template": "email = {{subject.mail.0}}"
|
||||
},
|
||||
{
|
||||
"helper": "certutil",
|
||||
"template": "email:{{subject.mail.0|quote}}"
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"data_source": "subject.mail.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"helper": "openssl",
|
||||
"template": "CN={{subject.krbprincipalname.0.partition('/')[2].partition('@')[0]}}"
|
||||
},
|
||||
{
|
||||
"helper": "certutil",
|
||||
"template": "CN={{subject.krbprincipalname.0.partition('/')[2].partition('@')[0]|quote}}"
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"data_source": "subject.krbprincipalname.0.partition('/')[2].partition('@')[0]"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"helper": "openssl",
|
||||
"template": "{{config.ipacertificatesubjectbase.0}}"
|
||||
},
|
||||
{
|
||||
"helper": "certutil",
|
||||
"template": "{{config.ipacertificatesubjectbase.0|quote}}"
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"data_source": "config.ipacertificatesubjectbase.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"helper": "openssl",
|
||||
"template": "CN={{subject.uid.0}}"
|
||||
},
|
||||
{
|
||||
"helper": "certutil",
|
||||
"template": "CN={{subject.uid.0|quote}}"
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"data_source": "subject.uid.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"helper": "openssl",
|
||||
"template": "subjectAltName = @{% call openssl.section() %}{{ datarules|join('\n') }}{% endcall %}",
|
||||
"options": {
|
||||
"extension": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"helper": "certutil",
|
||||
"template": "--extSAN {{ datarules|join(',') }}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"helper": "openssl",
|
||||
"template": "distinguished_name = {% call openssl.section() %}{{ datarules|reverse|join('\n') }}{% endcall %}"
|
||||
},
|
||||
{
|
||||
"helper": "certutil",
|
||||
"template": "-s {{ datarules|join(',') }}"
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"required": true,
|
||||
"data_source_combinator": "and"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
if [[ $# -lt 1 ]]; then
|
||||
echo "Usage: $0 <outfile> [<any> <certutil> <args>]"
|
||||
echo "Called as: $0 $@"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CSR="$1"
|
||||
shift
|
||||
certutil -R -a -z <(head -c 4096 /dev/urandom) -o "$CSR" {{ options|join(' ') }} "$@"
|
||||
@@ -0,0 +1,35 @@
|
||||
{% raw -%}
|
||||
{% import "openssl_macros.tmpl" as openssl -%}
|
||||
{%- endraw %}
|
||||
#!/bin/bash -e
|
||||
|
||||
if [[ $# -lt 2 ]]; then
|
||||
echo "Usage: $0 <outfile> <keyfile> <other openssl arguments>"
|
||||
echo "Called as: $0 $@"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CONFIG="$(mktemp)"
|
||||
CSR="$1"
|
||||
KEYFILE="$2"
|
||||
shift; shift
|
||||
|
||||
echo \
|
||||
{% raw %}{% filter quote %}{% endraw -%}
|
||||
[ req ]
|
||||
prompt = no
|
||||
encrypt_key = no
|
||||
|
||||
{{ parameters|join('\n') }}
|
||||
{% raw %}{% set rendered_extensions -%}{% endraw %}
|
||||
{{ extensions|join('\n') }}
|
||||
{% raw -%}
|
||||
{%- endset -%}
|
||||
{% if rendered_extensions -%}
|
||||
req_extensions = {% call openssl.section() %}{{ rendered_extensions }}{% endcall %}
|
||||
{% endif %}
|
||||
{{ openssl.openssl_sections|join('\n\n') }}
|
||||
{% endfilter %}{%- endraw %} > "$CONFIG"
|
||||
|
||||
openssl req -new -config "$CONFIG" -out "$CSR" -key "$KEYFILE" "$@"
|
||||
rm "$CONFIG"
|
||||
@@ -0,0 +1,29 @@
|
||||
{# List containing rendered sections to be included at end #}
|
||||
{% set openssl_sections = [] %}
|
||||
|
||||
{#
|
||||
List containing one entry for each section name allocated. Because of
|
||||
scoping rules, we need to use a list so that it can be a "per-render global"
|
||||
that gets updated in place. Real globals are shared by all templates with the
|
||||
same environment, and variables defined in the macro don't persist after the
|
||||
macro invocation ends.
|
||||
#}
|
||||
{% set openssl_section_num = [] %}
|
||||
|
||||
{% macro section() -%}
|
||||
{% set name -%}
|
||||
sec{{ openssl_section_num|length -}}
|
||||
{% endset -%}
|
||||
{% do openssl_section_num.append('') -%}
|
||||
{% set contents %}{{ caller() }}{% endset -%}
|
||||
{% if contents -%}
|
||||
{% set sectiondata = formatsection(name, contents) -%}
|
||||
{% do openssl_sections.append(sectiondata) -%}
|
||||
{% endif -%}
|
||||
{{ name -}}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro formatsection(name, contents) -%}
|
||||
[ {{ name }} ]
|
||||
{{ contents -}}
|
||||
{% endmacro %}
|
||||
+9
-1
@@ -43,6 +43,13 @@ if __name__ == '__main__':
|
||||
"ipaclient.remote_plugins.2_156",
|
||||
"ipaclient.remote_plugins.2_164",
|
||||
],
|
||||
package_data={
|
||||
'ipaclient': [
|
||||
'csrgen/profiles/*.json',
|
||||
'csrgen/rules/*.json',
|
||||
'csrgen/templates/*.tmpl',
|
||||
],
|
||||
},
|
||||
install_requires=[
|
||||
"cryptography",
|
||||
"ipalib",
|
||||
@@ -56,5 +63,6 @@ if __name__ == '__main__':
|
||||
extras_require={
|
||||
"install": ["ipaplatform"],
|
||||
"otptoken_yubikey": ["yubico", "usb"]
|
||||
}
|
||||
},
|
||||
zip_safe=False,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user