knife-ec-backup 2.4.12 → 2.4.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -21
- data/lib/chef/automate.rb +18 -0
- data/lib/chef/knife/ec_base.rb +18 -4
- data/lib/chef/knife/ec_key_base.rb +46 -16
- data/lib/knife_ec_backup/version.rb +1 -1
- data/spec/chef/knife/ec_backup_spec.rb +2 -0
- data/spec/chef/knife/ec_key_base_spec.rb +4 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddb6a9c53f5ef60525564d583b9906c746c3af34b8fe25fe92d8e0f362d1f039
|
4
|
+
data.tar.gz: '04987273e967c37af6b3738bac962349f07edc5a4db1a0ec13c0004093adc8af'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab40c44efddf1418bf52ed6d329b4e8d4419c927dbdcbfc758440d53b178183747c333c9019bbaec16b59750ec0432e9bf7397bcd651e978445abfe2f4515b4d
|
7
|
+
data.tar.gz: b5a4137aca897ffcf811e1c96fc87b3ffeb435337ac1aaf1a2301ed9ea0683983da8c1991daa9ce5413d6551453de98e2c99c6f8cb1156420f78a5104d9919e6
|
data/README.md
CHANGED
@@ -18,24 +18,24 @@ text format. It is similar to the `knife download` and `knife upload`
|
|
18
18
|
commands and uses the same underlying libraries, but also includes
|
19
19
|
workarounds for objects not yet supported by those tools and various
|
20
20
|
Server API deficiencies. The long-run goal is to improve `knife
|
21
|
-
download`, `knife upload` and the Chef Server API and deprecate this
|
21
|
+
download`, `knife upload` and the Chef Infra Server API and deprecate this
|
22
22
|
tool.
|
23
23
|
|
24
24
|
## Requirements
|
25
25
|
|
26
|
-
This knife plugin requires Chef Client 11.8+.
|
26
|
+
This knife plugin requires Chef Infra Client 11.8+.
|
27
27
|
|
28
28
|
### Server Support
|
29
29
|
|
30
|
-
This plugin currently supports Enterprise Chef 11 and Chef Server 12+.
|
30
|
+
This plugin currently supports Enterprise Chef 11 and Chef Infra Server 12+.
|
31
31
|
Support for the beta key rotation features is provided via the
|
32
32
|
`--with-keys-sql` flag, but users of this feature should note that
|
33
|
-
this may change once the Chef Server supports an API-based export of
|
33
|
+
this may change once the Chef Infra Server supports an API-based export of
|
34
34
|
the key data.
|
35
35
|
|
36
36
|
## Installation
|
37
37
|
|
38
|
-
### Chef Server Install (Recommended)
|
38
|
+
### Chef Infra Server Install (Recommended)
|
39
39
|
|
40
40
|
This gem is installed with chef-server-core 12.0.0 and newer.
|
41
41
|
|
@@ -57,6 +57,24 @@ on your system, try the following:
|
|
57
57
|
|
58
58
|
/opt/opscode/embedded/bin/gem install knife-ec-backup -- --with-pg-config=/opt/opscode/embedded/postgresql/9.2/bin/pg_config
|
59
59
|
|
60
|
+
This uses the libpq headers that are included in the Chef Infra Server
|
61
|
+
package installed in `/opt/opscode`.
|
62
|
+
|
63
|
+
### Chef Workstation Install (Unsupported)
|
64
|
+
|
65
|
+
On systems other than the Chef Infra Server, installation of this gem is not
|
66
|
+
tested or supported. However, if you attempt to do so you will need the
|
67
|
+
postgresql libraries installed.
|
68
|
+
|
69
|
+
For example, on macOS:
|
70
|
+
|
71
|
+
```
|
72
|
+
brew install libpq
|
73
|
+
gem install knife-ec-backup -- --with-pg-config=/usr/local/Cellar/libpq/9.2/bin/pg_config
|
74
|
+
```
|
75
|
+
|
76
|
+
The current location of pg_config can be determined with `brew info libpq`.
|
77
|
+
|
60
78
|
## Running tests
|
61
79
|
|
62
80
|
```
|
@@ -84,8 +102,8 @@ Clone the git repository and run the following from inside:
|
|
84
102
|
### Permissions
|
85
103
|
|
86
104
|
Note that most users in an EC installation lack the permissions to pull all of the data from all organizations and other users.
|
87
|
-
This plugin **REQUIRES THE PIVOTAL KEY AND WEBUI KEY** from the Chef Server.
|
88
|
-
It is recommended that you run this from a frontend Enterprise Chef Server, you can use --user and --key to pass the pivotal information along.
|
105
|
+
This plugin **REQUIRES THE PIVOTAL KEY AND WEBUI KEY** from the Chef Infra Server.
|
106
|
+
It is recommended that you run this from a frontend Enterprise Chef Infra Server, you can use --user and --key to pass the pivotal information along.
|
89
107
|
|
90
108
|
## Subcommands
|
91
109
|
|
@@ -94,14 +112,14 @@ It is recommended that you run this from a frontend Enterprise Chef Server, you
|
|
94
112
|
The following options are supported across all subcommands:
|
95
113
|
|
96
114
|
* `--sql-host`:
|
97
|
-
The hostname of the Chef Server's postgresql server. (default: localhost)
|
115
|
+
The hostname of the Chef Infra Server's postgresql server. (default: localhost)
|
98
116
|
|
99
117
|
* `--sql-port`:
|
100
|
-
The postgresql listening port on the Chef Server. (default: 5432)
|
118
|
+
The postgresql listening port on the Chef Infra Server. (default: 5432)
|
101
119
|
|
102
120
|
* `--sql-db`:
|
103
|
-
The postgresql Chef Server database name. (default: opscode_chef)
|
104
|
-
Specify 'automate-cs-oc-erchef' when using Automate Chef Server API
|
121
|
+
The postgresql Chef Infra Server database name. (default: opscode_chef)
|
122
|
+
Specify 'automate-cs-oc-erchef' when using Automate Chef Infra Server API
|
105
123
|
|
106
124
|
* `--sql-user`:
|
107
125
|
The username of postgresql user with access to the opscode_chef
|
@@ -139,8 +157,8 @@ The following options are supported across all subcommands:
|
|
139
157
|
|
140
158
|
* `--with-key-sql`: Whether to backup/restore key data directly
|
141
159
|
from the database. This requires access to the listening
|
142
|
-
postgresql port on the Chef Server. This is required to correctly
|
143
|
-
handle keys in Chef Servers with multikey support. This option
|
160
|
+
postgresql port on the Chef Infra Server. This is required to correctly
|
161
|
+
handle keys in Chef Infra Servers with multikey support. This option
|
144
162
|
will only work on `restore` if it was also used during the
|
145
163
|
`backup`.
|
146
164
|
|
@@ -151,7 +169,7 @@ The following options are supported across all subcommands:
|
|
151
169
|
Chef objects.
|
152
170
|
|
153
171
|
* `--skip-version-check`:
|
154
|
-
Skip Chef Server version check. This will also skip any auto-configured options (default: false)
|
172
|
+
Skip Chef Infra Server version check. This will also skip any auto-configured options (default: false)
|
155
173
|
|
156
174
|
* `--only-org ORG`:
|
157
175
|
Only donwload/restore objects in the named organization. Global
|
@@ -234,7 +252,7 @@ Private Chef server. DEST_DIR should be a backup directory created by
|
|
234
252
|
Server. (default: 10)
|
235
253
|
|
236
254
|
* `--skip-version-check`:
|
237
|
-
Skip Chef Server version check. This will
|
255
|
+
Skip Chef Infra Server version check. This will
|
238
256
|
also skip any auto-configured options (default: false)
|
239
257
|
|
240
258
|
* `--[no-]skip-user-ids`:
|
@@ -251,8 +269,8 @@ Private Chef server. DEST_DIR should be a backup directory created by
|
|
251
269
|
|
252
270
|
* `--with-key-sql`: Whether to backup/restore key data directly
|
253
271
|
from the database. This requires access to the listening
|
254
|
-
postgresql port on the Chef Server. This is required to correctly
|
255
|
-
handle keys in Chef Servers with multikey support. This option
|
272
|
+
postgresql port on the Chef Infra Server. This is required to correctly
|
273
|
+
handle keys in Chef Infra Servers with multikey support. This option
|
256
274
|
will only work on `restore` if it was also used during the
|
257
275
|
`backup`.
|
258
276
|
|
@@ -268,7 +286,7 @@ Private Chef server. DEST_DIR should be a backup directory created by
|
|
268
286
|
|
269
287
|
### knife ec key export [FILENAME]
|
270
288
|
|
271
|
-
Create a json representation of the users table from the Chef Server
|
289
|
+
Create a json representation of the users table from the Chef Infra Server
|
272
290
|
database. If no argument is given, the name of the backup is
|
273
291
|
`key_dump.json`.
|
274
292
|
|
@@ -278,7 +296,7 @@ Please note, most users should use `knife ec backup` with the
|
|
278
296
|
### knife ec key import [FILENAME]
|
279
297
|
|
280
298
|
Import a json representation of the users table from FILENAME to the
|
281
|
-
the Chef Server database. If no argument is given, the filename is
|
299
|
+
the Chef Infra Server database. If no argument is given, the filename is
|
282
300
|
assumed to be `key_dump.json`.
|
283
301
|
|
284
302
|
Please note, most user should use `knife ec restore` with the
|
@@ -287,11 +305,11 @@ Please note, most user should use `knife ec restore` with the
|
|
287
305
|
## Known Bugs
|
288
306
|
|
289
307
|
- knife-ec-backup cannot be installed in the embedded gemset of Chef
|
290
|
-
Server 12. This will be resolved in a future Chef Server release.
|
308
|
+
Server 12. This will be resolved in a future Chef Infra Server release.
|
291
309
|
|
292
310
|
- `knife ec restore` can fail to restore cookbooks, failing with an
|
293
311
|
internal server error. A common cause of this problem is a
|
294
|
-
concurrency bug in Chef Server. Setting `--concurrency 1` can often
|
312
|
+
concurrency bug in Chef Infra Server. Setting `--concurrency 1` can often
|
295
313
|
work around the issue.
|
296
314
|
|
297
315
|
- `knife ec restore` can fail if the pool of pre-created organizations
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Chef
|
2
|
+
class Automate
|
3
|
+
def self.is_installed?
|
4
|
+
File.exists?('/hab/svc/automate-cs-oc-erchef/')
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.config
|
8
|
+
{
|
9
|
+
sql_user: 'automate-cs-oc-erchef',
|
10
|
+
sql_cert: '/hab/svc/automate-cs-oc-erchef/config/service.crt',
|
11
|
+
sql_key: '/hab/svc/automate-cs-oc-erchef/config/service.key',
|
12
|
+
sql_rootcert: '/hab/svc/automate-cs-oc-erchef/config/root_ca.crt',
|
13
|
+
sql_db: 'automate-cs-oc-erchef',
|
14
|
+
webui_key: '/hab/svc/automate-cs-oc-erchef/data/webui_priv.pem'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/chef/knife/ec_base.rb
CHANGED
@@ -18,9 +18,10 @@
|
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
20
|
require 'chef/server_api'
|
21
|
-
require 'veil'
|
21
|
+
require 'veil' unless defined?(Veil)
|
22
22
|
require_relative 'ec_error_handler'
|
23
23
|
require 'ffi_yajl' unless defined?(FFI_Yajl)
|
24
|
+
require_relative '../automate'
|
24
25
|
|
25
26
|
class Chef
|
26
27
|
class Knife
|
@@ -41,7 +42,7 @@ class Chef
|
|
41
42
|
|
42
43
|
option :webui_key,
|
43
44
|
:long => '--webui-key KEYPATH',
|
44
|
-
:description => 'Path to the WebUI Key (default: Read from secrets store or /etc/opscode/webui_priv.pem)'
|
45
|
+
:description => 'Path to the WebUI Key (default: Read from secrets store or /etc/opscode/webui_priv.pem or /hab/svc/automate-cs-oc-erchef/data/webui_priv.pem)'
|
45
46
|
|
46
47
|
option :secrets_file_path,
|
47
48
|
:long => '--secrets-file PATH',
|
@@ -76,8 +77,7 @@ class Chef
|
|
76
77
|
|
77
78
|
option :sql_db,
|
78
79
|
:long => '--sql-db DBNAME',
|
79
|
-
:description => 'Postgresql Chef Server database name (default: opscode_chef)'
|
80
|
-
:default => "opscode_chef"
|
80
|
+
:description => 'Postgresql Chef Server database name (default: opscode_chef or automate-cs-oc-erchef)'
|
81
81
|
|
82
82
|
option :sql_user,
|
83
83
|
:long => "--sql-user USERNAME",
|
@@ -87,6 +87,18 @@ class Chef
|
|
87
87
|
:long => "--sql-password PASSWORD",
|
88
88
|
:description => 'Password used to connect to the postgresql database'
|
89
89
|
|
90
|
+
option :sql_cert,
|
91
|
+
:long => "--sql-cert ",
|
92
|
+
:description => 'Path to client ssl cert'
|
93
|
+
|
94
|
+
option :sql_key,
|
95
|
+
:long => "--sql-key PATH",
|
96
|
+
:description => 'Path to client ssl key'
|
97
|
+
|
98
|
+
option :sql_rootcert,
|
99
|
+
:long => "--sql-rootcert ",
|
100
|
+
:description => 'Path to root ssl cert'
|
101
|
+
|
90
102
|
option :with_user_sql,
|
91
103
|
:long => '--with-user-sql',
|
92
104
|
:description => 'Try direct data base access for user export/import. Required to properly handle passwords, keys, and USAGs'
|
@@ -200,6 +212,8 @@ class Chef
|
|
200
212
|
def webui_key
|
201
213
|
if config[:webui_key]
|
202
214
|
config[:webui_key]
|
215
|
+
elsif Chef::Automate.is_installed?
|
216
|
+
config[:webui_key] = Chef::Automate.config[:webui_key]
|
203
217
|
elsif veil.exist?("chef-server", "webui_key")
|
204
218
|
temporary_webui_key
|
205
219
|
else
|
@@ -17,6 +17,7 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
|
+
require 'veil'
|
20
21
|
|
21
22
|
class Chef
|
22
23
|
class Knife
|
@@ -28,6 +29,7 @@ class Chef
|
|
28
29
|
deps do
|
29
30
|
require 'sequel'
|
30
31
|
require 'json' unless defined?(JSON)
|
32
|
+
require_relative '../automate'
|
31
33
|
end
|
32
34
|
|
33
35
|
option :sql_host,
|
@@ -42,8 +44,7 @@ class Chef
|
|
42
44
|
|
43
45
|
option :sql_db,
|
44
46
|
:long => '--sql-db DBNAME',
|
45
|
-
:description => 'Postgresql Chef Server database name (default: opscode_chef)'
|
46
|
-
:default => "opscode_chef"
|
47
|
+
:description => 'Postgresql Chef Server database name (default: opscode_chef or automate-cs-oc-erchef)'
|
47
48
|
|
48
49
|
option :sql_user,
|
49
50
|
:long => "--sql-user USERNAME",
|
@@ -53,6 +54,18 @@ class Chef
|
|
53
54
|
:long => "--sql-password PASSWORD",
|
54
55
|
:description => 'Password used to connect to the postgresql database'
|
55
56
|
|
57
|
+
option :sql_cert,
|
58
|
+
:long => "--sql-cert ",
|
59
|
+
:description => 'Path to client ssl cert'
|
60
|
+
|
61
|
+
option :sql_key,
|
62
|
+
:long => "--sql-key PATH",
|
63
|
+
:description => 'Path to client ssl key'
|
64
|
+
|
65
|
+
option :sql_rootcert,
|
66
|
+
:long => "--sql-rootcert ",
|
67
|
+
:description => 'Path to root ssl cert'
|
68
|
+
|
56
69
|
option :secrets_file_path,
|
57
70
|
:long => '--secrets-file PATH',
|
58
71
|
:description => 'Path to a valid private-chef-secrets.json file (default: /etc/opscode/private-chef-secrets.json)',
|
@@ -73,27 +86,44 @@ class Chef
|
|
73
86
|
def db
|
74
87
|
@db ||= begin
|
75
88
|
require 'sequel'
|
76
|
-
|
77
|
-
|
89
|
+
require 'uri'
|
90
|
+
server_uri = URI('postgres://')
|
91
|
+
server_uri.host = config[:sql_host]
|
92
|
+
server_uri.port = config[:sql_port]
|
93
|
+
server_uri.user = URI.encode_www_form_component(config[:sql_user]) if config[:sql_user]
|
94
|
+
server_uri.password = URI.encode_www_form_component(config[:sql_password]) if config[:sql_password]
|
95
|
+
query_params = []
|
96
|
+
query_params.push("sslcert=#{config[:sql_cert]}") if config[:sql_cert]
|
97
|
+
query_params.push("sslkey=#{config[:sql_key]}") if config[:sql_key]
|
98
|
+
query_params.push("sslrootcert=#{config[:sql_rootcert]}") if config[:sql_rootcert]
|
99
|
+
server_uri.query = query_params.join("&") if query_params.length > 0
|
100
|
+
|
101
|
+
::Sequel.connect(server_uri.to_s, :convert_infinite_timestamps => :string)
|
78
102
|
end
|
79
103
|
end
|
80
104
|
|
81
105
|
# Loads SQL user and password from running config if not passed
|
82
106
|
# as a command line option
|
83
107
|
def load_config_from_file!
|
84
|
-
if
|
85
|
-
ui.
|
86
|
-
|
108
|
+
if Chef::Automate.is_installed?
|
109
|
+
ui.msg "Automate detected"
|
110
|
+
config.merge! Chef::Automate.config {|key, v1, v2| v1}
|
87
111
|
else
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
112
|
+
if ! File.exists?("/etc/opscode/chef-server-running.json")
|
113
|
+
ui.fatal "SQL User or Password not provided as option and running config cannot be found!"
|
114
|
+
exit 1
|
115
|
+
else
|
116
|
+
running_config ||= JSON.parse(File.read("/etc/opscode/chef-server-running.json"))
|
117
|
+
# Latest versions of chef server put the database info under opscode-erchef.sql_user
|
118
|
+
hash_key = if running_config['private_chef']['opscode-erchef'].has_key? 'sql_user'
|
119
|
+
'opscode-erchef'
|
120
|
+
else
|
121
|
+
'postgresql'
|
122
|
+
end
|
123
|
+
config[:sql_user] ||= running_config['private_chef'][hash_key]['sql_user']
|
124
|
+
config[:sql_password] ||= (running_config['private_chef'][hash_key]['sql_password'] || sql_password)
|
125
|
+
config[:sql_db] ||= 'opscode_chef'
|
126
|
+
end
|
97
127
|
end
|
98
128
|
end
|
99
129
|
|
@@ -38,6 +38,8 @@ describe Chef::Knife::EcBackup do
|
|
38
38
|
allow(@knife).to receive(:rest).and_return(@rest)
|
39
39
|
allow(@knife).to receive(:user_acl_rest).and_return(@rest)
|
40
40
|
allow_any_instance_of(Chef::Knife::EcBase).to receive(:dest_dir).and_return(dest_dir)
|
41
|
+
allow(@knife.ui).to receive(:msg)
|
42
|
+
allow(@knife.ui).to receive(:error)
|
41
43
|
end
|
42
44
|
|
43
45
|
describe "#for_each_user" do
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
|
2
2
|
require 'chef/knife/ec_key_base'
|
3
|
+
require 'chef/automate'
|
3
4
|
|
4
5
|
class KeyBaseTester < Chef::Knife
|
5
6
|
include Chef::Knife::EcKeyBase
|
@@ -9,15 +10,16 @@ describe Chef::Knife::EcKeyBase do
|
|
9
10
|
let (:knife) { KeyBaseTester.new }
|
10
11
|
|
11
12
|
let(:running_server_postgresql_sql_config_json) {
|
12
|
-
'{"private_chef": { "opscode-erchef":{}, "postgresql": { "sql_user": "jiminy", "sql_password": "secret"} }
|
13
|
+
'{"private_chef": { "opscode-erchef":{}, "postgresql": { "sql_user": "jiminy", "sql_password": "secret"} } }'
|
13
14
|
}
|
14
15
|
|
15
16
|
|
16
17
|
let(:running_server_erchef_config_json) {
|
17
|
-
'{"private_chef": { "opscode-erchef": { "sql_user": "cricket", "sql_password": "secrete"}}
|
18
|
+
'{"private_chef": { "opscode-erchef": { "sql_user": "cricket", "sql_password": "secrete"} } }'
|
18
19
|
}
|
19
20
|
describe "#load_config_from_file!" do
|
20
21
|
before(:each) do
|
22
|
+
allow(Chef::Automate).to receive(:is_installed?).and_return(false)
|
21
23
|
allow(File).to receive(:exists?).and_return(true)
|
22
24
|
allow(File).to receive(:size).and_return(1)
|
23
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-ec-backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- LICENSE
|
92
92
|
- README.md
|
93
93
|
- Rakefile
|
94
|
+
- lib/chef/automate.rb
|
94
95
|
- lib/chef/knife/ec_backup.rb
|
95
96
|
- lib/chef/knife/ec_base.rb
|
96
97
|
- lib/chef/knife/ec_error_handler.rb
|
@@ -114,7 +115,7 @@ files:
|
|
114
115
|
- spec/spec_helper.rb
|
115
116
|
homepage: https://www.chef.io
|
116
117
|
licenses:
|
117
|
-
- Apache
|
118
|
+
- Apache-2.0
|
118
119
|
metadata: {}
|
119
120
|
post_install_message:
|
120
121
|
rdoc_options: []
|
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
132
|
- !ruby/object:Gem::Version
|
132
133
|
version: '0'
|
133
134
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
135
|
+
rubygems_version: 3.1.4
|
135
136
|
signing_key:
|
136
137
|
specification_version: 4
|
137
138
|
summary: Backup and Restore of Enterprise Chef
|