blob: e931da8424a44f82666cf0233a2e1c527c1442e3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002#ifndef _FS_CEPH_AUTH_H
3#define _FS_CEPH_AUTH_H
4
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07005#include <linux/ceph/types.h>
6#include <linux/ceph/buffer.h>
Sage Weil4e7a5dc2009-11-18 16:19:57 -08007
8/*
9 * Abstract interface for communicating with the authenticate module.
10 * There is some handshake that takes place between us and the monitor
11 * to acquire the necessary keys. These are used to generate an
12 * 'authorizer' that we use when connecting to a service (mds, osd).
13 */
14
15struct ceph_auth_client;
Yan, Zheng33d07332014-11-04 16:33:37 +080016struct ceph_msg;
Sage Weil4e7a5dc2009-11-18 16:19:57 -080017
Ilya Dryomov6c1ea262016-04-11 19:34:49 +020018struct ceph_authorizer {
19 void (*destroy)(struct ceph_authorizer *);
20};
21
Alex Elder6c4a1912012-05-16 15:16:38 -050022struct ceph_auth_handshake {
23 struct ceph_authorizer *authorizer;
24 void *authorizer_buf;
25 size_t authorizer_buf_len;
26 void *authorizer_reply_buf;
27 size_t authorizer_reply_buf_len;
Yan, Zheng33d07332014-11-04 16:33:37 +080028 int (*sign_message)(struct ceph_auth_handshake *auth,
29 struct ceph_msg *msg);
30 int (*check_message_signature)(struct ceph_auth_handshake *auth,
31 struct ceph_msg *msg);
Alex Elder6c4a1912012-05-16 15:16:38 -050032};
33
Sage Weil4e7a5dc2009-11-18 16:19:57 -080034struct ceph_auth_client_ops {
Sage Weil559c1e02010-05-14 09:55:18 -070035 const char *name;
36
Sage Weil4e7a5dc2009-11-18 16:19:57 -080037 /*
38 * true if we are authenticated and can connect to
39 * services.
40 */
41 int (*is_authenticated)(struct ceph_auth_client *ac);
42
43 /*
Sage Weila41359f2010-05-25 15:39:06 -070044 * true if we should (re)authenticate, e.g., when our tickets
45 * are getting old and crusty.
46 */
47 int (*should_authenticate)(struct ceph_auth_client *ac);
48
49 /*
Sage Weil4e7a5dc2009-11-18 16:19:57 -080050 * build requests and process replies during monitor
51 * handshake. if handle_reply returns -EAGAIN, we build
52 * another request.
53 */
54 int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
55 int (*handle_reply)(struct ceph_auth_client *ac, int result,
56 void *buf, void *end);
57
58 /*
59 * Create authorizer for connecting to a service, and verify
60 * the response to authenticate the service.
61 */
62 int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
Alex Elder74f18692012-05-16 15:16:39 -050063 struct ceph_auth_handshake *auth);
Sage Weil0bed9b52013-03-25 10:26:01 -070064 /* ensure that an existing authorizer is up to date */
65 int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
66 struct ceph_auth_handshake *auth);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080067 int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
Ilya Dryomov0dde5842016-12-02 16:35:09 +010068 struct ceph_authorizer *a);
Sage Weil9bd2e6f2010-02-02 16:21:06 -080069 void (*invalidate_authorizer)(struct ceph_auth_client *ac,
70 int peer_type);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080071
72 /* reset when we (re)connect to a monitor */
73 void (*reset)(struct ceph_auth_client *ac);
74
75 void (*destroy)(struct ceph_auth_client *ac);
Yan, Zheng33d07332014-11-04 16:33:37 +080076
77 int (*sign_message)(struct ceph_auth_handshake *auth,
78 struct ceph_msg *msg);
79 int (*check_message_signature)(struct ceph_auth_handshake *auth,
80 struct ceph_msg *msg);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080081};
82
83struct ceph_auth_client {
84 u32 protocol; /* CEPH_AUTH_* */
85 void *private; /* for use by protocol implementation */
86 const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
87
88 bool negotiating; /* true if negotiating protocol */
89 const char *name; /* entity name */
90 u64 global_id; /* our unique id in system */
Tommi Virtanen8323c3a2011-03-25 16:32:57 -070091 const struct ceph_crypto_key *key; /* our secret key */
Sage Weil4e7a5dc2009-11-18 16:19:57 -080092 unsigned want_keys; /* which services we want */
Sage Weile9966072013-03-25 10:26:30 -070093
94 struct mutex mutex;
Sage Weil4e7a5dc2009-11-18 16:19:57 -080095};
96
97extern struct ceph_auth_client *ceph_auth_init(const char *name,
Tommi Virtanen8323c3a2011-03-25 16:32:57 -070098 const struct ceph_crypto_key *key);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080099extern void ceph_auth_destroy(struct ceph_auth_client *ac);
100
101extern void ceph_auth_reset(struct ceph_auth_client *ac);
102
103extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
104 void *buf, size_t len);
105extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
106 void *buf, size_t len,
107 void *reply_buf, size_t reply_len);
Ilya Dryomovf01d5cb2016-06-02 16:45:08 +0200108int ceph_auth_entity_name_encode(const char *name, void **p, void *end);
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800109
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800110extern int ceph_build_auth(struct ceph_auth_client *ac,
111 void *msg_buf, size_t msg_len);
112
113extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
Sage Weil27859f92013-03-25 10:26:14 -0700114extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
115 int peer_type,
116 struct ceph_auth_handshake *auth);
Ilya Dryomov6c1ea262016-04-11 19:34:49 +0200117void ceph_auth_destroy_authorizer(struct ceph_authorizer *a);
Sage Weil27859f92013-03-25 10:26:14 -0700118extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
119 int peer_type,
120 struct ceph_auth_handshake *a);
121extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
Ilya Dryomov0dde5842016-12-02 16:35:09 +0100122 struct ceph_authorizer *a);
Sage Weil27859f92013-03-25 10:26:14 -0700123extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,
124 int peer_type);
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800125
Yan, Zheng33d07332014-11-04 16:33:37 +0800126static inline int ceph_auth_sign_message(struct ceph_auth_handshake *auth,
127 struct ceph_msg *msg)
128{
129 if (auth->sign_message)
130 return auth->sign_message(auth, msg);
131 return 0;
132}
133
134static inline
135int ceph_auth_check_message_signature(struct ceph_auth_handshake *auth,
136 struct ceph_msg *msg)
137{
138 if (auth->check_message_signature)
139 return auth->check_message_signature(auth, msg);
140 return 0;
141}
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800142#endif