blob: 260d78b587c48e99f552f328a27a65ddd9745dd2 [file] [log] [blame]
Sage Weil4e7a5dc2009-11-18 16:19:57 -08001#ifndef _FS_CEPH_AUTH_H
2#define _FS_CEPH_AUTH_H
3
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07004#include <linux/ceph/types.h>
5#include <linux/ceph/buffer.h>
Sage Weil4e7a5dc2009-11-18 16:19:57 -08006
7/*
8 * Abstract interface for communicating with the authenticate module.
9 * There is some handshake that takes place between us and the monitor
10 * to acquire the necessary keys. These are used to generate an
11 * 'authorizer' that we use when connecting to a service (mds, osd).
12 */
13
14struct ceph_auth_client;
15struct ceph_authorizer;
Yan, Zheng33d07332014-11-04 16:33:37 +080016struct ceph_msg;
Sage Weil4e7a5dc2009-11-18 16:19:57 -080017
Alex Elder6c4a1912012-05-16 15:16:38 -050018struct ceph_auth_handshake {
19 struct ceph_authorizer *authorizer;
20 void *authorizer_buf;
21 size_t authorizer_buf_len;
22 void *authorizer_reply_buf;
23 size_t authorizer_reply_buf_len;
Yan, Zheng33d07332014-11-04 16:33:37 +080024 int (*sign_message)(struct ceph_auth_handshake *auth,
25 struct ceph_msg *msg);
26 int (*check_message_signature)(struct ceph_auth_handshake *auth,
27 struct ceph_msg *msg);
Alex Elder6c4a1912012-05-16 15:16:38 -050028};
29
Sage Weil4e7a5dc2009-11-18 16:19:57 -080030struct ceph_auth_client_ops {
Sage Weil559c1e02010-05-14 09:55:18 -070031 const char *name;
32
Sage Weil4e7a5dc2009-11-18 16:19:57 -080033 /*
34 * true if we are authenticated and can connect to
35 * services.
36 */
37 int (*is_authenticated)(struct ceph_auth_client *ac);
38
39 /*
Sage Weila41359f2010-05-25 15:39:06 -070040 * true if we should (re)authenticate, e.g., when our tickets
41 * are getting old and crusty.
42 */
43 int (*should_authenticate)(struct ceph_auth_client *ac);
44
45 /*
Sage Weil4e7a5dc2009-11-18 16:19:57 -080046 * build requests and process replies during monitor
47 * handshake. if handle_reply returns -EAGAIN, we build
48 * another request.
49 */
50 int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
51 int (*handle_reply)(struct ceph_auth_client *ac, int result,
52 void *buf, void *end);
53
54 /*
55 * Create authorizer for connecting to a service, and verify
56 * the response to authenticate the service.
57 */
58 int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
Alex Elder74f18692012-05-16 15:16:39 -050059 struct ceph_auth_handshake *auth);
Sage Weil0bed9b52013-03-25 10:26:01 -070060 /* ensure that an existing authorizer is up to date */
61 int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
62 struct ceph_auth_handshake *auth);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080063 int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
64 struct ceph_authorizer *a, size_t len);
65 void (*destroy_authorizer)(struct ceph_auth_client *ac,
66 struct ceph_authorizer *a);
Sage Weil9bd2e6f2010-02-02 16:21:06 -080067 void (*invalidate_authorizer)(struct ceph_auth_client *ac,
68 int peer_type);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080069
70 /* reset when we (re)connect to a monitor */
71 void (*reset)(struct ceph_auth_client *ac);
72
73 void (*destroy)(struct ceph_auth_client *ac);
Yan, Zheng33d07332014-11-04 16:33:37 +080074
75 int (*sign_message)(struct ceph_auth_handshake *auth,
76 struct ceph_msg *msg);
77 int (*check_message_signature)(struct ceph_auth_handshake *auth,
78 struct ceph_msg *msg);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080079};
80
81struct ceph_auth_client {
82 u32 protocol; /* CEPH_AUTH_* */
83 void *private; /* for use by protocol implementation */
84 const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
85
86 bool negotiating; /* true if negotiating protocol */
87 const char *name; /* entity name */
88 u64 global_id; /* our unique id in system */
Tommi Virtanen8323c3a2011-03-25 16:32:57 -070089 const struct ceph_crypto_key *key; /* our secret key */
Sage Weil4e7a5dc2009-11-18 16:19:57 -080090 unsigned want_keys; /* which services we want */
Sage Weile9966072013-03-25 10:26:30 -070091
92 struct mutex mutex;
Sage Weil4e7a5dc2009-11-18 16:19:57 -080093};
94
95extern struct ceph_auth_client *ceph_auth_init(const char *name,
Tommi Virtanen8323c3a2011-03-25 16:32:57 -070096 const struct ceph_crypto_key *key);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080097extern void ceph_auth_destroy(struct ceph_auth_client *ac);
98
99extern void ceph_auth_reset(struct ceph_auth_client *ac);
100
101extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
102 void *buf, size_t len);
103extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
104 void *buf, size_t len,
105 void *reply_buf, size_t reply_len);
106extern int ceph_entity_name_encode(const char *name, void **p, void *end);
107
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800108extern int ceph_build_auth(struct ceph_auth_client *ac,
109 void *msg_buf, size_t msg_len);
110
111extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
Sage Weil27859f92013-03-25 10:26:14 -0700112extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
113 int peer_type,
114 struct ceph_auth_handshake *auth);
115extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
116 struct ceph_authorizer *a);
117extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
118 int peer_type,
119 struct ceph_auth_handshake *a);
120extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
121 struct ceph_authorizer *a,
122 size_t len);
123extern 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