Merge "deploy.sh: Retire simplest scenario fallback"
[fuel.git] / mcp / patches / 0011-system.repo-Debian-Add-keyserver-proxy-support.patch
1 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
2 Date: Mon, 22 Jan 2018 00:28:09 +0100
3 Subject: [PATCH] system.repo: Debian: Add keyserver proxy support
4
5 Introduce a new, optional set of parameters to configure the proxy
6 used for key fetching / keyserver access under:
7 linux:system:proxy:keyserver:http(s).
8
9 Previously, when fetching GPG keys for APT keyring, either using
10 public key download & import (as for default repos) or via keyserver,
11 we relied on simple `curl` calls or passed it down to Salt aptpkg
12 module.
13 To be able to retrieve APT keys behind a proxy, one used to have to
14 configure the proxy for the Salt minion, which does not yet have
15 `no_proxy` support (either *all* or *no* traffic hits the proxy).
16
17 When the new http(s) proxy param is set:
18 - no longer pass key configuration to Salt aptpkg (until it properly
19   supports `no_proxy`);
20 - handle all keys explicitly with `curl` and `apt-key`;
21 - set 'http(s)_proxy' env vars for `cmd.run`/`cmd.wait` calls;
22
23 If linux:system:proxy:keyserver is not defined, the behavior is
24 unchanged for backwards compatibility.
25
26 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
27 ---
28  README.rst            | 16 ++++++++++++++++
29  linux/system/repo.sls | 40 ++++++++++++++++++++++++++++++++++++++++
30  2 files changed, 56 insertions(+)
31
32 diff --git a/linux/system/repo.sls b/linux/system/repo.sls
33 index 5d4d059..724db5a 100644
34 --- a/linux/system/repo.sls
35 +++ b/linux/system/repo.sls
36 @@ -96,13 +96,50 @@ linux_repo_{{ name }}_key:
37      - name: "curl -s {{ repo.key_url }} | apt-key add -"
38      - watch:
39        - file: default_repo_list
40 +{%- if system.proxy.keyserver is defined %}
41 +    - env:
42 +      - http_proxy: {{ system.proxy.get('keyserver', {}).get('http', '') }}
43 +      - https_proxy: {{ system.proxy.get('keyserver', {}).get('https', '') }}
44 +{%- endif %}
45
46  {%- endif %}
47
48 +{#- repo.default is false #}
49  {%- else %}
50
51  {%- if repo.get('enabled', True) %}
52
53 +{%- if system.proxy.keyserver is defined %}
54 +
55 +{%- if repo.get('key') %}
56 +
57 +linux_repo_{{ name }}_key:
58 +  cmd.run:
59 +    - name: "echo '{{ repo.key }}' | apt-key add -"
60 +
61 +{%- elif repo.key_url|default(False) %}
62 +
63 +linux_repo_{{ name }}_key:
64 +  cmd.run:
65 +    - name: "curl -s {{ repo.key_url }} | apt-key add -"
66 +    - env:
67 +      - http_proxy: {{ system.proxy.get('keyserver', {}).get('http', '') }}
68 +      - https_proxy: {{ system.proxy.get('keyserver', {}).get('https', '') }}
69 +
70 +{%- elif repo.key_id is defined and repo.key_server is defined %}
71 +
72 +linux_repo_{{ name }}_key:
73 +  cmd.run:
74 +    - name: "apt-key adv --keyserver {{ repo.key_server }} --recv {{ repo.key_id }}"
75 +    - env:
76 +      - http_proxy: {{ system.proxy.get('keyserver', {}).get('http', '') }}
77 +      - https_proxy: {{ system.proxy.get('keyserver', {}).get('https', '') }}
78 +
79 +{%- endif %}
80 +
81 +{#- system.proxy.keyserver #}
82 +{%- endif %}
83 +
84  linux_repo_{{ name }}:
85    pkgrepo.managed:
86    {%- if repo.ppa is defined %}
87 @@ -115,6 +152,7 @@ linux_repo_{{ name }}:
88    {%- endif %}
89    - file: /etc/apt/sources.list.d/{{ name }}.list
90    - clean_file: {{ repo.clean|default(True) }}
91 +  {%- if system.proxy.keyserver is not defined %}
92    {%- if repo.key_id is defined %}
93    - keyid: {{ repo.key_id }}
94    {%- endif %}
95 @@ -124,6 +162,7 @@ linux_repo_{{ name }}:
96    {%- if repo.key_url is defined %}
97    - key_url: {{ repo.key_url }}
98    {%- endif %}
99 +  {%- endif %}
100    - consolidate: {{ repo.get('consolidate', False) }}
101    - clean_file: {{ repo.get('clean_file', False) }}
102    - refresh_db: {{ repo.get('refresh_db', True) }}
103 @@ -140,6 +179,7 @@ linux_repo_{{ name }}:
104    {%- endif %}
105    {%- endif %}
106
107 +{#- repo.enabled is false #}
108  {%- else %}
109
110  linux_repo_{{ name }}_absent: