Skip to content

Commit

Permalink
auth: 'ceph auth import -i' overwrites caps, if caps are not specified
Browse files Browse the repository at this point in the history
in given keyring file, should alert user and should not allow this import.
Because in 'ceph auth list' we keep all the keyrings with caps and importing
'client.admin' user keyring without caps locks the cluster with error[1]
because admin keyring caps are missing in 'ceph auth'.

[1] Error connecting to cluster: PermissionDeniedError

Fixes: http://tracker.ceph.com/issues/18932

Signed-off-by: Vikhyat Umrao <vumrao@redhat.com>
(cherry picked from commit 90144aa)
  • Loading branch information
vumrao authored and shinobu-x committed Feb 20, 2017
1 parent c9ece04 commit 7c6c3c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions qa/workunits/cephtool/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ function test_auth()
#
local auid=444
ceph-authtool --create-keyring --name client.TEST --gen-key --set-uid $auid TEST-keyring
expect_false ceph auth import --in-file TEST-keyring
rm TEST-keyring
ceph-authtool --create-keyring --name client.TEST --gen-key --cap mon "allow r" --set-uid $auid TEST-keyring
ceph auth import --in-file TEST-keyring
rm TEST-keyring
ceph auth get client.TEST > $TMPFILE
Expand Down
15 changes: 13 additions & 2 deletions src/mon/AuthMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,15 @@ void AuthMonitor::export_keyring(KeyRing& keyring)
mon->key_server.export_keyring(keyring);
}

void AuthMonitor::import_keyring(KeyRing& keyring)
int AuthMonitor::import_keyring(KeyRing& keyring)
{
for (map<EntityName, EntityAuth>::iterator p = keyring.get_keys().begin();
p != keyring.get_keys().end();
++p) {
if (p->second.caps.empty()) {
dout(0) << "import: no caps supplied" << dendl;
return -EINVAL;
}
KeyServerData::Incremental auth_inc;
auth_inc.name = p->first;
auth_inc.auth = p->second;
Expand All @@ -665,6 +669,7 @@ void AuthMonitor::import_keyring(KeyRing& keyring)
dout(30) << " " << auth_inc.auth << dendl;
push_cephx_inc(auth_inc);
}
return 0;
}

bool AuthMonitor::prepare_command(MonOpRequestRef op)
Expand Down Expand Up @@ -731,7 +736,13 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op)
rs = err;
goto done;
}
import_keyring(keyring);
err = import_keyring(keyring);
if (err < 0) {
ss << "auth import: no caps supplied";
getline(ss, rs);
mon->reply_command(op, -EINVAL, rs, get_last_committed());
return true;
}
ss << "imported keyring";
getline(ss, rs);
err = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mon/AuthMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class AuthMonitor : public PaxosService {
void upgrade_format();

void export_keyring(KeyRing& keyring);
void import_keyring(KeyRing& keyring);
int import_keyring(KeyRing& keyring);

void push_cephx_inc(KeyServerData::Incremental& auth_inc) {
Incremental inc;
Expand Down

0 comments on commit 7c6c3c7

Please sign in to comment.