[virtual] Split 'pxebr' from 'mcpcontrol' net
[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 To allow runtime decisions whether the keyserver proxy should be used
35 add an additional condition for it to match the first nameserver.
36 This allows us to mix virtual nodes with MaaS-provisioned nodes in
37 Fuel@OPNFV, while keeping the ext_pillar common.
38
39 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
40 ---
41  README.rst            | 16 ++++++++++++++++
42  linux/system/repo.sls | 40 ++++++++++++++++++++++++++++++++++++++++
43  2 files changed, 56 insertions(+)
44
45 diff --git a/linux/system/repo.sls b/linux/system/repo.sls
46 --- a/linux/system/repo.sls
47 +++ b/linux/system/repo.sls
48 @@ -96,13 +96,50 @@ linux_repo_{{ name }}_key:
49      - name: "curl -s {{ repo.key_url }} | apt-key add -"
50      - watch:
51        - file: default_repo_list
52 +{%- if system.proxy.keyserver is defined and grains['dns']['nameservers'][0] in system.proxy.keyserver.http %}
53 +    - env:
54 +      - http_proxy: {{ system.proxy.get('keyserver', {}).get('http', '') }}
55 +      - https_proxy: {{ system.proxy.get('keyserver', {}).get('https', '') }}
56 +{%- endif %}
57
58  {%- endif %}
59
60 +{#- repo.default is false #}
61  {%- else %}
62
63  {%- if repo.get('enabled', True) %}
64
65 +{%- if system.proxy.keyserver is defined and grains['dns']['nameservers'][0] in system.proxy.keyserver.http %}
66 +
67 +{%- if repo.get('key') %}
68 +
69 +linux_repo_{{ name }}_key:
70 +  cmd.run:
71 +    - name: "echo '{{ repo.key }}' | apt-key add -"
72 +
73 +{%- elif repo.key_url|default(False) %}
74 +
75 +linux_repo_{{ name }}_key:
76 +  cmd.run:
77 +    - name: "curl -s {{ repo.key_url }} | apt-key add -"
78 +    - env:
79 +      - http_proxy: {{ system.proxy.get('keyserver', {}).get('http', '') }}
80 +      - https_proxy: {{ system.proxy.get('keyserver', {}).get('https', '') }}
81 +
82 +{%- elif repo.key_id is defined and repo.key_server is defined %}
83 +
84 +linux_repo_{{ name }}_key:
85 +  cmd.run:
86 +    - name: "apt-key adv --keyserver {{ repo.key_server }} --recv {{ repo.key_id }}"
87 +    - env:
88 +      - http_proxy: {{ system.proxy.get('keyserver', {}).get('http', '') }}
89 +      - https_proxy: {{ system.proxy.get('keyserver', {}).get('https', '') }}
90 +
91 +{%- endif %}
92 +
93 +{#- system.proxy.keyserver #}
94 +{%- endif %}
95 +
96  linux_repo_{{ name }}:
97    pkgrepo.managed:
98    {%- if repo.ppa is defined %}
99 @@ -115,6 +152,7 @@ linux_repo_{{ name }}:
100    {%- endif %}
101    - file: /etc/apt/sources.list.d/{{ name }}.list
102    - clean_file: {{ repo.clean|default(True) }}
103 +  {%- if system.proxy.keyserver is not defined or grains['dns']['nameservers'][0] not in system.proxy.keyserver.http %}
104    {%- if repo.key_id is defined %}
105    - keyid: {{ repo.key_id }}
106    {%- endif %}
107 @@ -124,6 +162,7 @@ linux_repo_{{ name }}:
108    {%- if repo.key_url is defined %}
109    - key_url: {{ repo.key_url }}
110    {%- endif %}
111 +  {%- endif %}
112    - consolidate: {{ repo.get('consolidate', False) }}
113    - clean_file: {{ repo.get('clean_file', False) }}
114    - refresh_db: {{ repo.get('refresh_db', True) }}
115 @@ -140,6 +179,7 @@ linux_repo_{{ name }}:
116    {%- endif %}
117    {%- endif %}
118
119 +{#- repo.enabled is false #}
120  {%- else %}
121
122  linux_repo_{{ name }}_absent: