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