knife-ec-backup 2.4.7 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -74
- data/Rakefile +1 -1
- data/lib/chef/automate.rb +18 -0
- data/lib/chef/knife/ec_backup.rb +11 -20
- data/lib/chef/knife/ec_base.rb +27 -9
- data/lib/chef/knife/ec_key_base.rb +49 -19
- data/lib/chef/knife/ec_key_export.rb +2 -2
- data/lib/chef/knife/ec_key_import.rb +1 -1
- data/lib/chef/knife/ec_restore.rb +10 -6
- data/lib/chef/server.rb +2 -2
- data/lib/knife_ec_backup/version.rb +1 -1
- data/spec/chef/knife/ec_backup_spec.rb +4 -2
- data/spec/chef/knife/ec_base_spec.rb +1 -1
- data/spec/chef/knife/ec_key_base_spec.rb +4 -2
- data/spec/chef/knife/ec_key_export_spec.rb +2 -2
- data/spec/chef/knife/ec_restore_spec.rb +2 -1
- data/spec/chef/server_spec.rb +8 -8
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29f71b880bfbb21dba4529c4a03f9966d208a7f39c478613d3e38d1130ca5c06
|
4
|
+
data.tar.gz: 6196ae8cc2a56309310c5c25d7392dd3a1dfd7367a9d0994639998aa42f48422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edb3a2500bb5c15b5a9c2b786152e2677f495e1996492411584a7fd3d91bf4d60b89e834a0fccf58388f7013f94a73c8ebf8c52df52c884530a2f62782aa9a6e
|
7
|
+
data.tar.gz: 43b2cb7433041e8f1d7654147205c5d769f582de6e40b3f5f482cda0a7b3b4b712c19ed7f05e1bcf55f6de184297e150f833f9621cd0f82d050a3b1bea049687
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Knife EC Backup
|
2
|
-
[![Build
|
2
|
+
[![Build status](https://badge.buildkite.com/4bc85427aab66accafbd7abb2932b9dd7f9208162c5be33488.svg?branch=master)](https://buildkite.com/chef-oss/chef-knife-ec-backup-master-verify)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/knife-ec-backup.svg)](https://badge.fury.io/rb/knife-ec-backup)
|
4
4
|
|
5
5
|
**Umbrella Project**: [Knife](https://github.com/chef/chef-oss-practices/blob/master/projects/knife.md)
|
@@ -10,57 +10,59 @@
|
|
10
10
|
|
11
11
|
**Pull Request [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md)**: 14 days
|
12
12
|
|
13
|
-
|
13
|
+
## Description
|
14
14
|
|
15
|
-
knife-ec-backup can backup and restore the data in
|
15
|
+
knife-ec-backup can backup and restore the data in a Chef Infra
|
16
16
|
Server installation, preserving the data in an intermediate, editable
|
17
17
|
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
|
-
Server API deficiencies. The long-run goal is to improve `knife
|
21
|
-
download`, `knife upload` and the Chef Server API and deprecate this
|
20
|
+
Infra Server API deficiencies. The long-run goal is to improve `knife
|
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
|
-
|
31
|
-
of this gem. Version 1.x additionally depends on knife-essentials.
|
32
|
-
|
33
|
-
## Server Support
|
34
|
-
|
35
|
-
This plugin currently supports Enterprise Chef 11 and Chef Server 12.
|
30
|
+
This plugin currently supports Chef Infra Server 12+.
|
36
31
|
Support for the beta key rotation features is provided via the
|
37
32
|
`--with-keys-sql` flag, but users of this feature should note that
|
38
|
-
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
|
39
34
|
the key data.
|
40
35
|
|
41
|
-
|
36
|
+
## Installation
|
42
37
|
|
43
|
-
|
38
|
+
### Chef Infra Server Install (Recommended)
|
44
39
|
|
45
|
-
This gem is installed with
|
40
|
+
This gem is installed with Chef Infra Server 12 and later and the sub-commands are available with embedded copy of `knife`, e.g.:
|
46
41
|
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
```
|
43
|
+
sudo /opt/opscode/bin/knife ec backup ~/chef-server-backup-directory
|
44
|
+
```
|
45
|
+
|
46
|
+
If you need a newer version of `knife-ec-backup` than is on the server you wish to back up, you can install it using the embedded `gem` command.
|
50
47
|
|
51
48
|
```
|
52
|
-
/opt/opscode/embedded/bin/gem
|
53
|
-
/opt/opscode/embedded/bin/gem install knife-ec-backup*gem --no-ri --no-rdoc -V
|
49
|
+
/opt/opscode/embedded/bin/gem install knife-ec-backup --no-doc
|
54
50
|
```
|
55
51
|
|
56
|
-
###
|
52
|
+
### Chef Workstation Install (Unsupported)
|
57
53
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
on your system, try the following:
|
54
|
+
On systems other than the Chef Infra Server, installation of this gem is not
|
55
|
+
tested or supported. However, if you attempt to do so you will need the
|
56
|
+
postgresql libraries installed.
|
62
57
|
|
63
|
-
|
58
|
+
For example, on macOS:
|
59
|
+
|
60
|
+
```
|
61
|
+
brew install libpq
|
62
|
+
gem install knife-ec-backup -- --with-pg-config=/usr/local/Cellar/libpq/9.2/bin/pg_config
|
63
|
+
```
|
64
|
+
|
65
|
+
The current location of pg_config can be determined with `brew info libpq`.
|
64
66
|
|
65
67
|
## Running tests
|
66
68
|
|
@@ -84,29 +86,29 @@ Clone the git repository and run the following from inside:
|
|
84
86
|
gem build knife-ec-backup.gemspec
|
85
87
|
gem install knife-ec-backup*gem
|
86
88
|
|
87
|
-
|
89
|
+
## Configuration
|
88
90
|
|
89
|
-
|
91
|
+
### Permissions
|
90
92
|
|
91
|
-
Note that most users in
|
92
|
-
This plugin **REQUIRES THE PIVOTAL KEY AND WEBUI KEY** from the Chef Server.
|
93
|
-
It is recommended that you run this from a frontend
|
93
|
+
Note that most users in a Chef Infra Server installation lack the permissions to pull all of the data from all organizations and other users.
|
94
|
+
This plugin **REQUIRES THE PIVOTAL KEY AND WEBUI KEY** from the Chef Infra Server.
|
95
|
+
It is recommended that you run this from a frontend Chef Infra Server. You can use `--user pivotal --key /path/to/pivotal.pem` to provide a path to the `pivotal` key.
|
94
96
|
|
95
|
-
|
97
|
+
## Subcommands
|
96
98
|
|
97
|
-
|
99
|
+
### Common Options
|
98
100
|
|
99
101
|
The following options are supported across all subcommands:
|
100
102
|
|
101
103
|
* `--sql-host`:
|
102
|
-
The hostname of the Chef Server's postgresql server. (default: localhost)
|
104
|
+
The hostname of the Chef Infra Server's postgresql server. (default: localhost)
|
103
105
|
|
104
106
|
* `--sql-port`:
|
105
|
-
The postgresql listening port on the Chef Server. (default: 5432)
|
107
|
+
The postgresql listening port on the Chef Infra Server. (default: 5432)
|
106
108
|
|
107
109
|
* `--sql-db`:
|
108
|
-
The postgresql Chef Server database name. (default: opscode_chef)
|
109
|
-
Specify 'automate-cs-oc-erchef' when using Automate Chef Server API
|
110
|
+
The postgresql Chef Infra Server database name. (default: opscode_chef)
|
111
|
+
Specify 'automate-cs-oc-erchef' when using Automate Chef Infra Server API
|
110
112
|
|
111
113
|
* `--sql-user`:
|
112
114
|
The username of postgresql user with access to the opscode_chef
|
@@ -122,9 +124,9 @@ The following options are supported across all subcommands:
|
|
122
124
|
* `--dry-run`:
|
123
125
|
Report what actions would be taken without performing any. (default: false)
|
124
126
|
|
125
|
-
|
127
|
+
### knife ec backup DEST_DIR (options)
|
126
128
|
|
127
|
-
*Path*: If you have
|
129
|
+
*Path*: If you have Chef Infra Client installed on this server, you may need to invoke this as `/opt/opscode/bin/knife ec backup BACKUP_DIRECTORY`
|
128
130
|
|
129
131
|
*Options*
|
130
132
|
|
@@ -144,8 +146,8 @@ The following options are supported across all subcommands:
|
|
144
146
|
|
145
147
|
* `--with-key-sql`: Whether to backup/restore key data directly
|
146
148
|
from the database. This requires access to the listening
|
147
|
-
postgresql port on the Chef Server. This is required to correctly
|
148
|
-
handle keys in Chef Servers with multikey support. This option
|
149
|
+
postgresql port on the Chef Infra Server. This is required to correctly
|
150
|
+
handle keys in Chef Infra Servers with multikey support. This option
|
149
151
|
will only work on `restore` if it was also used during the
|
150
152
|
`backup`.
|
151
153
|
|
@@ -156,13 +158,13 @@ The following options are supported across all subcommands:
|
|
156
158
|
Chef objects.
|
157
159
|
|
158
160
|
* `--skip-version-check`:
|
159
|
-
Skip Chef Server version check. This will also skip any auto-configured options (default: false)
|
161
|
+
Skip Chef Infra Server version check. This will also skip any auto-configured options (default: false)
|
160
162
|
|
161
163
|
* `--only-org ORG`:
|
162
164
|
Only donwload/restore objects in the named organization. Global
|
163
165
|
objects such as users will still be downloaded/restored.
|
164
166
|
|
165
|
-
Creates a repository of an entire
|
167
|
+
Creates a repository of an entire Chef Infra Server
|
166
168
|
|
167
169
|
The format of the repository is based on the `knife-essentials` (`knife download`) format and looks like this:
|
168
170
|
|
@@ -214,10 +216,9 @@ This compares very closely with the "knife download /" from an OSC server:
|
|
214
216
|
users
|
215
217
|
<name>.json>
|
216
218
|
|
217
|
-
|
219
|
+
### knife ec restore DEST_DIR (options)
|
218
220
|
|
219
|
-
Restores all data from the specified DEST_DIR to
|
220
|
-
Private Chef server. DEST_DIR should be a backup directory created by
|
221
|
+
Restores all data from the specified DEST_DIR to a Chef Infra Server. DEST_DIR should be a backup directory created by
|
221
222
|
`knife ec backup`
|
222
223
|
|
223
224
|
*Options*
|
@@ -239,11 +240,11 @@ Private Chef server. DEST_DIR should be a backup directory created by
|
|
239
240
|
Server. (default: 10)
|
240
241
|
|
241
242
|
* `--skip-version-check`:
|
242
|
-
Skip Chef Server version check. This will
|
243
|
+
Skip Chef Infra Server version check. This will
|
243
244
|
also skip any auto-configured options (default: false)
|
244
245
|
|
245
246
|
* `--[no-]skip-user-ids`:
|
246
|
-
Reuses user ids from the restore destination when updating existing
|
247
|
+
Reuses user ids from the restore destination when updating existing
|
247
248
|
users to avoid database conflicts (default: true)
|
248
249
|
|
249
250
|
* `--with-user-sql`:
|
@@ -256,8 +257,8 @@ Private Chef server. DEST_DIR should be a backup directory created by
|
|
256
257
|
|
257
258
|
* `--with-key-sql`: Whether to backup/restore key data directly
|
258
259
|
from the database. This requires access to the listening
|
259
|
-
postgresql port on the Chef Server. This is required to correctly
|
260
|
-
handle keys in Chef Servers with multikey support. This option
|
260
|
+
postgresql port on the Chef Infra Server. This is required to correctly
|
261
|
+
handle keys in Chef Infra Servers with multikey support. This option
|
261
262
|
will only work on `restore` if it was also used during the
|
262
263
|
`backup`.
|
263
264
|
|
@@ -268,44 +269,31 @@ Private Chef server. DEST_DIR should be a backup directory created by
|
|
268
269
|
Chef objects.
|
269
270
|
|
270
271
|
* `--only-org ORG`:
|
271
|
-
Only
|
272
|
+
Only download/restore objects in the named organization. Global
|
272
273
|
objects such as users will still be downloaded/restored.
|
273
274
|
|
274
|
-
|
275
|
+
### knife ec key export [FILENAME]
|
275
276
|
|
276
|
-
Create a json representation of the users table from the Chef Server
|
277
|
+
Create a json representation of the users table from the Chef Infra Server
|
277
278
|
database. If no argument is given, the name of the backup is
|
278
279
|
`key_dump.json`.
|
279
280
|
|
280
281
|
Please note, most users should use `knife ec backup` with the
|
281
282
|
`--with-user-sql` option rather than this command.
|
282
283
|
|
283
|
-
|
284
|
+
### knife ec key import [FILENAME]
|
284
285
|
|
285
286
|
Import a json representation of the users table from FILENAME to the
|
286
|
-
the Chef Server database. If no argument is given, the filename is
|
287
|
+
the Chef Infra Server database. If no argument is given, the filename is
|
287
288
|
assumed to be `key_dump.json`.
|
288
289
|
|
289
|
-
Please note, most
|
290
|
+
Please note, most users should use `knife ec restore` with the
|
290
291
|
`--with-user-sql` option rather than this command.
|
291
292
|
|
292
|
-
|
293
|
-
|
294
|
-
- knife-ec-backup cannot be installed in the embedded gemset of Chef
|
295
|
-
Server 12. This will be resolved in a future Chef Server release.
|
293
|
+
## Known Bugs
|
296
294
|
|
297
295
|
- `knife ec restore` can fail to restore cookbooks, failing with an
|
298
296
|
internal server error. A common cause of this problem is a
|
299
|
-
concurrency bug in Chef Server. Setting `--concurrency 1` can often
|
297
|
+
concurrency bug in Chef Infra Server. Setting `--concurrency 1` can often
|
300
298
|
work around the issue.
|
301
299
|
|
302
|
-
- `knife ec restore` can fail if the pool of pre-created organizations
|
303
|
-
can not keep up with the newly created organizations. This can
|
304
|
-
typically be resolved simply be restarting the restore. To avoid
|
305
|
-
this error for backups with large number of organizations, try
|
306
|
-
setting (in /etc/opscode/private-chef.rb):
|
307
|
-
|
308
|
-
opscode_org_creator['ready_org_depth']
|
309
|
-
|
310
|
-
to the number of organizations in your backup and waiting for the
|
311
|
-
pool to fill before running `knife ec restore`
|
data/Rakefile
CHANGED
@@ -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_backup.rb
CHANGED
@@ -13,9 +13,13 @@ class Chef
|
|
13
13
|
require 'chef/chef_fs/config'
|
14
14
|
require 'chef/chef_fs/file_system'
|
15
15
|
require 'chef/chef_fs/file_pattern'
|
16
|
-
|
16
|
+
begin
|
17
|
+
require 'chef/chef_fs/parallelizer'
|
18
|
+
rescue LoadError
|
19
|
+
require 'chef-utils/parallel_map' unless defined?(ChefUtils::ParallelMap)
|
20
|
+
end
|
17
21
|
require_relative '../server'
|
18
|
-
require 'fileutils'
|
22
|
+
require 'fileutils' unless defined?(FileUtils)
|
19
23
|
end
|
20
24
|
|
21
25
|
def run
|
@@ -30,7 +34,7 @@ class Chef
|
|
30
34
|
for_each_user do |username, url|
|
31
35
|
download_user(username, url)
|
32
36
|
if config[:skip_useracl]
|
33
|
-
ui.warn("Skipping user ACL download for #{username}. To download this ACL, remove --skip-useracl
|
37
|
+
ui.warn("Skipping user ACL download for #{username}. To download this ACL, remove --skip-useracl.")
|
34
38
|
else
|
35
39
|
download_user_acl(username)
|
36
40
|
end
|
@@ -96,10 +100,10 @@ class Chef
|
|
96
100
|
knife_ec_error_handler.add(ex)
|
97
101
|
next
|
98
102
|
end
|
99
|
-
# Enterprise Chef 11 and below uses a pool of
|
103
|
+
# Enterprise Chef 11 and below uses a pool of pre-created
|
100
104
|
# organizations to account for slow organization creation
|
101
105
|
# using CouchDB. Thus, on server versions < 12 we want to
|
102
|
-
# skip any of these
|
106
|
+
# skip any of these pre-created organizations by checking if
|
103
107
|
# they have been assigned or not. The Chef 12 API does not
|
104
108
|
# return an assigned_at field.
|
105
109
|
if org['assigned_at'] || server.version >= Gem::Version.new("12")
|
@@ -192,13 +196,6 @@ class Chef
|
|
192
196
|
# Download the billing-admins, public_key_read_access ACL and group as pivotal
|
193
197
|
chef_fs_config = Chef::ChefFS::Config.new
|
194
198
|
|
195
|
-
paths = ['/acls/groups/billing-admins.json', '/groups/billing-admins.json', '/groups/admins.json']
|
196
|
-
paths.push('/acls/groups/public_key_read_access.json', '/groups/public_key_read_access.json') if server.supports_public_key_read_access?
|
197
|
-
|
198
|
-
paths.each do |path|
|
199
|
-
chef_fs_copy_pattern(path, chef_fs_config)
|
200
|
-
end
|
201
|
-
|
202
199
|
Chef::Config.node_name = if config[:skip_version]
|
203
200
|
org_admin
|
204
201
|
else
|
@@ -206,7 +203,7 @@ class Chef
|
|
206
203
|
end
|
207
204
|
|
208
205
|
chef_fs_config = Chef::ChefFS::Config.new
|
209
|
-
top_level_paths = chef_fs_config.chef_fs.children.
|
206
|
+
top_level_paths = chef_fs_config.chef_fs.children.map { |entry| entry.path }
|
210
207
|
|
211
208
|
# The top level acl object names end with .json extension
|
212
209
|
# Therefore we can use Chef::ChefFS::FilePattern matching for items
|
@@ -216,13 +213,7 @@ class Chef
|
|
216
213
|
# therefore we use normalize_path_name to add the .json extension
|
217
214
|
# for example: /acls/environments/_default
|
218
215
|
|
219
|
-
|
220
|
-
exclude_list = ['billing-admins', 'public_key_read_access']
|
221
|
-
|
222
|
-
top_level_acls = chef_fs_paths('/acls/*.json', chef_fs_config, [])
|
223
|
-
acl_paths = chef_fs_paths('/acls/*/*', chef_fs_config, exclude_list)
|
224
|
-
group_paths = chef_fs_paths('/groups/*', chef_fs_config, exclude_list)
|
225
|
-
(top_level_paths + top_level_acls + acl_paths + group_paths).each do |path|
|
216
|
+
top_level_paths.each do |path|
|
226
217
|
chef_fs_copy_pattern(path, chef_fs_config)
|
227
218
|
end
|
228
219
|
ensure
|
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
|
-
require 'ffi_yajl'
|
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',
|
@@ -58,7 +59,7 @@ class Chef
|
|
58
59
|
:long => '--skip-version-check',
|
59
60
|
:boolean => true,
|
60
61
|
:default => false,
|
61
|
-
:description => "Skip Chef Server version check. This will also skip any auto-configured options"
|
62
|
+
:description => "Skip Chef Infra Server version check. This will also skip any auto-configured options"
|
62
63
|
|
63
64
|
option :org,
|
64
65
|
:long => "--only-org ORG",
|
@@ -66,18 +67,17 @@ class Chef
|
|
66
67
|
|
67
68
|
option :sql_host,
|
68
69
|
:long => '--sql-host HOSTNAME',
|
69
|
-
:description => '
|
70
|
+
:description => 'PostgreSQL database hostname (default: localhost)',
|
70
71
|
:default => "localhost"
|
71
72
|
|
72
73
|
option :sql_port,
|
73
74
|
:long => '--sql-port PORT',
|
74
|
-
:description => '
|
75
|
+
:description => 'PostgreSQL database port (default: 5432)',
|
75
76
|
:default => 5432
|
76
77
|
|
77
78
|
option :sql_db,
|
78
79
|
:long => '--sql-db DBNAME',
|
79
|
-
:description => '
|
80
|
-
:default => "opscode_chef"
|
80
|
+
:description => 'PostgreSQL Chef Infra 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'
|
@@ -113,7 +125,11 @@ class Chef
|
|
113
125
|
def configure_chef
|
114
126
|
super
|
115
127
|
Chef::Config[:concurrency] = config[:concurrency].to_i if config[:concurrency]
|
116
|
-
Chef::ChefFS::Parallelizer
|
128
|
+
if defined?(Chef::ChefFS::Parallelizer)
|
129
|
+
Chef::ChefFS::Parallelizer.threads = (Chef::Config[:concurrency] || 10) - 1
|
130
|
+
elsif defined?(ChefUtils::DefaultThreadPool)
|
131
|
+
ChefUtils::DefaultThreadPool.instance.threads = (Chef::Config[:concurrency] || 10) - 1
|
132
|
+
end
|
117
133
|
end
|
118
134
|
|
119
135
|
def org_admin
|
@@ -200,6 +216,8 @@ class Chef
|
|
200
216
|
def webui_key
|
201
217
|
if config[:webui_key]
|
202
218
|
config[:webui_key]
|
219
|
+
elsif Chef::Automate.is_installed?
|
220
|
+
config[:webui_key] = Chef::Automate.config[:webui_key]
|
203
221
|
elsif veil.exist?("chef-server", "webui_key")
|
204
222
|
temporary_webui_key
|
205
223
|
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
|
@@ -27,23 +28,23 @@ class Chef
|
|
27
28
|
|
28
29
|
deps do
|
29
30
|
require 'sequel'
|
30
|
-
require 'json'
|
31
|
+
require 'json' unless defined?(JSON)
|
32
|
+
require_relative '../automate'
|
31
33
|
end
|
32
34
|
|
33
35
|
option :sql_host,
|
34
36
|
:long => '--sql-host HOSTNAME',
|
35
|
-
:description => '
|
37
|
+
:description => 'PostgreSQL database hostname (default: localhost)',
|
36
38
|
:default => "localhost"
|
37
39
|
|
38
40
|
option :sql_port,
|
39
41
|
:long => '--sql-port PORT',
|
40
|
-
:description => '
|
42
|
+
:description => 'PostgreSQL database port (default: 5432)',
|
41
43
|
:default => 5432
|
42
44
|
|
43
45
|
option :sql_db,
|
44
46
|
:long => '--sql-db DBNAME',
|
45
|
-
:description => '
|
46
|
-
:default => "opscode_chef"
|
47
|
+
:description => 'PostgreSQL Chef Infra 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 Infra 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
|
|
@@ -43,8 +43,8 @@ class Chef
|
|
43
43
|
export_keys(key_data_path) unless config[:skip_keys_table]
|
44
44
|
rescue Sequel::DatabaseError => e
|
45
45
|
if e.message =~ /^PG::UndefinedTable/
|
46
|
-
ui.error "Keys table not found. The keys table only exists on Chef Server 12."
|
47
|
-
ui.error "Chef Server 11 users should use the --skip-keys-table option to avoid this error."
|
46
|
+
ui.error "Keys table not found. The keys table only exists on Chef Infra Server 12."
|
47
|
+
ui.error "Chef Infra Server 11 users should use the --skip-keys-table option to avoid this error."
|
48
48
|
exit 1
|
49
49
|
else
|
50
50
|
raise
|
@@ -184,7 +184,7 @@ class Chef
|
|
184
184
|
d.delete('id') if config[:skip_ids]
|
185
185
|
# If the hash_type in the export,
|
186
186
|
# we are dealing with a record where the password is still in the
|
187
|
-
#
|
187
|
+
# serialized_object. Explicitly setting these to nil ensures that the
|
188
188
|
# password set in the restore is wiped out.
|
189
189
|
unless d.has_key?('hash_type')
|
190
190
|
d['hash_type'] = nil
|
@@ -33,8 +33,12 @@ class Chef
|
|
33
33
|
# Work around bug in chef_fs
|
34
34
|
require 'chef/chef_fs/command_line'
|
35
35
|
require 'chef/chef_fs/data_handler/acl_data_handler'
|
36
|
-
require 'securerandom'
|
37
|
-
|
36
|
+
require 'securerandom' unless defined?(SecureRandom)
|
37
|
+
begin
|
38
|
+
require 'chef/chef_fs/parallelizer'
|
39
|
+
rescue LoadError
|
40
|
+
require 'chef-utils/parallel_map' unless defined?(ChefUtils::ParallelMap)
|
41
|
+
end
|
38
42
|
require_relative '../tsorter'
|
39
43
|
require_relative '../server'
|
40
44
|
end
|
@@ -61,7 +65,7 @@ class Chef
|
|
61
65
|
restore_key_sql if config[:with_key_sql]
|
62
66
|
|
63
67
|
if config[:skip_useracl]
|
64
|
-
ui.warn("Skipping user ACL update. To update user ACLs, remove --skip-useracl
|
68
|
+
ui.warn("Skipping user ACL update. To update user ACLs, remove --skip-useracl.")
|
65
69
|
else
|
66
70
|
restore_user_acls
|
67
71
|
end
|
@@ -229,7 +233,7 @@ class Chef
|
|
229
233
|
ui.msg "Restoring org admin data"
|
230
234
|
chef_fs_config = Chef::ChefFS::Config.new
|
231
235
|
|
232
|
-
# Handle Admins, Billing Admins and Public Key Read Access
|
236
|
+
# Handle Admins, Billing Admins and Public Key Read Access separately
|
233
237
|
#
|
234
238
|
# admins: We need to upload admins first so that we
|
235
239
|
# can upload all of the other objects as a user in the org
|
@@ -288,7 +292,7 @@ class Chef
|
|
288
292
|
# Store organization data in a particular order:
|
289
293
|
# - clients must be uploaded before groups (in top_level_paths)
|
290
294
|
# - groups must be uploaded before any acl's
|
291
|
-
# - groups must be uploaded twice to account for Chef Server versions that don't
|
295
|
+
# - groups must be uploaded twice to account for Chef Infra Server versions that don't
|
292
296
|
# accept group members on POST
|
293
297
|
(top_level_paths + group_paths*2 + group_acl_paths + acl_paths).each do |path|
|
294
298
|
chef_fs_copy_pattern(path, chef_fs_config)
|
@@ -305,7 +309,7 @@ class Chef
|
|
305
309
|
end
|
306
310
|
|
307
311
|
# ChefFS copy pattern inside the EcRestore class will
|
308
|
-
# copy from the local_fs to the Chef Server.
|
312
|
+
# copy from the local_fs to the Chef Infra Server.
|
309
313
|
#
|
310
314
|
# NOTE: Do not get confused, this is the other way around
|
311
315
|
# from how we implemented in EcBackup. Therefor we can't
|
data/lib/chef/server.rb
CHANGED
@@ -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
|
@@ -70,7 +72,7 @@ describe Chef::Knife::EcBackup do
|
|
70
72
|
expect{ |b| @knife.for_each_organization(&b) }.to yield_successive_args(org_response("bar"), org_response("foo"))
|
71
73
|
end
|
72
74
|
|
73
|
-
it "skips unassigned (precreated) organizations on Chef Server 11" do
|
75
|
+
it "skips unassigned (precreated) organizations on Chef Infra Server 11" do
|
74
76
|
server = double('Chef::Server')
|
75
77
|
allow(Chef::Server).to receive(:new).and_return(server)
|
76
78
|
allow(server).to receive(:version).and_return(Gem::Version.new("11.12.3"))
|
@@ -79,7 +81,7 @@ describe Chef::Knife::EcBackup do
|
|
79
81
|
expect{ |b| @knife.for_each_organization(&b) }.to yield_successive_args(org_response("bar"))
|
80
82
|
end
|
81
83
|
|
82
|
-
it "includes *all* organizations on Chef Server 12" do
|
84
|
+
it "includes *all* organizations on Chef Infra Server 12" do
|
83
85
|
server = double('Chef::Server')
|
84
86
|
allow(Chef::Server).to receive(:new).and_return(server)
|
85
87
|
allow(server).to receive(:version).and_return(Gem::Version.new("12.0.0"))
|
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_hel
|
|
2
2
|
require 'chef/knife/ec_base'
|
3
3
|
require 'chef/knife'
|
4
4
|
require 'chef/config'
|
5
|
-
require 'stringio'
|
5
|
+
require 'stringio' unless defined?(StringIO)
|
6
6
|
|
7
7
|
class Tester < Chef::Knife
|
8
8
|
include Chef::Knife::EcBase
|
@@ -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
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
|
2
2
|
require 'chef/knife/ec_key_export'
|
3
3
|
require 'sequel'
|
4
|
-
require 'json'
|
5
|
-
require 'securerandom'
|
4
|
+
require 'json' unless defined?(JSON)
|
5
|
+
require 'securerandom' unless defined?(SecureRandom)
|
6
6
|
require 'fakefs/spec_helpers'
|
7
7
|
|
8
8
|
def user_record(name)
|
@@ -3,6 +3,7 @@ require 'chef/knife/ec_restore'
|
|
3
3
|
require 'fakefs/spec_helpers'
|
4
4
|
require_relative './ec_error_handler_spec'
|
5
5
|
require "chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir"
|
6
|
+
require 'net/http'
|
6
7
|
|
7
8
|
def make_user(username)
|
8
9
|
FileUtils.mkdir_p("/users")
|
@@ -58,7 +59,7 @@ describe Chef::Knife::EcRestore do
|
|
58
59
|
@knife.restore_open_invitations("foo")
|
59
60
|
end
|
60
61
|
|
61
|
-
it "does NOT fail if an
|
62
|
+
it "does NOT fail if an invitation already exists" do
|
62
63
|
make_org "foo"
|
63
64
|
allow(@rest).to receive(:post).with("organizations/foo/association_requests", {"user" => "bob"}).and_return(net_exception(409))
|
64
65
|
allow(@rest).to receive(:post).with("organizations/foo/association_requests", {"user" => "jane"}).and_return(net_exception(409))
|
data/spec/chef/server_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
2
|
require 'chef/server'
|
3
3
|
require 'chef/server_api'
|
4
|
-
require 'stringio'
|
4
|
+
require 'stringio' unless defined?(StringIO)
|
5
5
|
|
6
6
|
describe Chef::Server do
|
7
7
|
before(:each) do
|
@@ -9,7 +9,7 @@ describe Chef::Server do
|
|
9
9
|
allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
|
10
10
|
end
|
11
11
|
|
12
|
-
it "infers root url from a Chef Server url" do
|
12
|
+
it "infers root url from a Chef Infra Server url" do
|
13
13
|
s = Chef::Server.from_chef_server_url("http://api.example.com/organizations/foobar")
|
14
14
|
expect(s.root_url).to eq("http://api.example.com")
|
15
15
|
end
|
@@ -28,22 +28,22 @@ describe Chef::Server do
|
|
28
28
|
|
29
29
|
it "determines the running omnibus server version" do
|
30
30
|
s = Chef::Server.new('http://api.example.com')
|
31
|
-
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Server 1.8.1\nother stuff\nother stuff"))
|
31
|
+
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Infra Server 1.8.1\nother stuff\nother stuff"))
|
32
32
|
expect(s.version.to_s).to eq('1.8.1')
|
33
33
|
end
|
34
34
|
|
35
35
|
it "ignores git tags when determining the version" do
|
36
36
|
s = Chef::Server.new("http://api.example.com")
|
37
|
-
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Server 1.8.1+20141024080718.git.16.08098a5\nother stuff\nother stuff"))
|
37
|
+
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Infra Server 1.8.1+20141024080718.git.16.08098a5\nother stuff\nother stuff"))
|
38
38
|
expect(s.version.to_s).to eq("1.8.1")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "knows whether the server supports user ACLs via nginx" do
|
42
42
|
s1 = Chef::Server.new("http://api.example.com")
|
43
|
-
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Server 11.0.0\nother stuff\nother stuff"))
|
43
|
+
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Infra Server 11.0.0\nother stuff\nother stuff"))
|
44
44
|
expect(s1.supports_user_acls?).to eq(false)
|
45
45
|
s2 = Chef::Server.new("http://api.example.com")
|
46
|
-
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Server 11.0.2\nother stuff\nother stuff"))
|
46
|
+
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Infra Server 11.0.2\nother stuff\nother stuff"))
|
47
47
|
expect(s2.supports_user_acls?).to eq(true)
|
48
48
|
end
|
49
49
|
|
@@ -61,10 +61,10 @@ describe Chef::Server do
|
|
61
61
|
|
62
62
|
it "knows that public_key_read_access was implemented in 12.5.0" do
|
63
63
|
before = Chef::Server.new("http://api.example.com")
|
64
|
-
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Server 12.4.1\nother stuff\nother stuff"))
|
64
|
+
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Infra Server 12.4.1\nother stuff\nother stuff"))
|
65
65
|
expect(before.supports_public_key_read_access?).to eq(false)
|
66
66
|
after = Chef::Server.new("http://api.example.com")
|
67
|
-
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Server 12.6.0\nother stuff\nother stuff"))
|
67
|
+
allow(@rest).to receive(:get).with("version").and_return(StringIO.new("Chef Infra Server 12.6.0\nother stuff\nother stuff"))
|
68
68
|
expect(after.supports_public_key_read_access?).to eq(true)
|
69
69
|
end
|
70
70
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-ec-backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
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: 2022-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pg
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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: []
|
@@ -124,14 +125,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
125
|
requirements:
|
125
126
|
- - ">="
|
126
127
|
- !ruby/object:Gem::Version
|
127
|
-
version: '
|
128
|
+
version: '2.6'
|
128
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
130
|
requirements:
|
130
131
|
- - ">="
|
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
|