1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.hbase.security.visibility; 19 20 import java.io.IOException; 21 import java.util.List; 22 23 import org.apache.hadoop.conf.Configurable; 24 import org.apache.hadoop.hbase.Tag; 25 import org.apache.hadoop.hbase.TagType; 26 import org.apache.hadoop.hbase.classification.InterfaceAudience; 27 import org.apache.hadoop.hbase.classification.InterfaceStability; 28 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; 29 import org.apache.hadoop.hbase.regionserver.OperationStatus; 30 import org.apache.hadoop.hbase.security.User; 31 32 /** 33 * The interface which deals with visibility labels and user auths admin service as well as the cell 34 * visibility expression storage part and read time evaluation. 35 */ 36 @InterfaceAudience.Public 37 @InterfaceStability.Evolving 38 public interface VisibilityLabelService extends Configurable { 39 40 /** 41 * System calls this after opening of regions. Gives a chance for the VisibilityLabelService to so 42 * any initialization logic. 43 * @param e 44 * the region coprocessor env 45 */ 46 void init(RegionCoprocessorEnvironment e) throws IOException; 47 48 /** 49 * Adds the set of labels into the system. 50 * @param labels 51 * Labels to add to the system. 52 * @return OperationStatus for each of the label addition 53 */ 54 OperationStatus[] addLabels(List<byte[]> labels) throws IOException; 55 56 /** 57 * Sets given labels globally authorized for the user. 58 * @param user 59 * The authorizing user 60 * @param authLabels 61 * Labels which are getting authorized for the user 62 * @return OperationStatus for each of the label auth addition 63 */ 64 OperationStatus[] setAuths(byte[] user, List<byte[]> authLabels) throws IOException; 65 66 /** 67 * Removes given labels from user's globally authorized list of labels. 68 * @param user 69 * The user whose authorization to be removed 70 * @param authLabels 71 * Labels which are getting removed from authorization set 72 * @return OperationStatus for each of the label auth removal 73 */ 74 OperationStatus[] clearAuths(byte[] user, List<byte[]> authLabels) throws IOException; 75 76 /** 77 * Retrieve the visibility labels for the user. 78 * @param user 79 * Name of the user whose authorization to be retrieved 80 * @param systemCall 81 * Whether a system or user originated call. 82 * @return Visibility labels authorized for the given user. 83 */ 84 List<String> getUserAuths(byte[] user, boolean systemCall) throws IOException; 85 86 /** 87 * Retrieve the visibility labels for the groups. 88 * @param groups 89 * Name of the groups whose authorization to be retrieved 90 * @param systemCall 91 * Whether a system or user originated call. 92 * @return Visibility labels authorized for the given group. 93 */ 94 List<String> getGroupAuths(String[] groups, boolean systemCall) throws IOException; 95 96 /** 97 * Retrieve the list of visibility labels defined in the system. 98 * @param regex The regular expression to filter which labels are returned. 99 * @return List of visibility labels 100 */ 101 List<String> listLabels(String regex) throws IOException; 102 103 /** 104 * Creates tags corresponding to given visibility expression. 105 * <br> 106 * Note: This will be concurrently called from multiple threads and implementation should 107 * take care of thread safety. 108 * @param visExpression The Expression for which corresponding Tags to be created. 109 * @param withSerializationFormat specifies whether a tag, denoting the serialization version 110 * of the tags, to be added in the list. When this is true make sure to add the 111 * serialization format Tag also. The format tag value should be byte type. 112 * @param checkAuths denotes whether to check individual labels in visExpression against user's 113 * global auth label. 114 * @return The list of tags corresponds to the visibility expression. These tags will be stored 115 * along with the Cells. 116 */ 117 List<Tag> createVisibilityExpTags(String visExpression, boolean withSerializationFormat, 118 boolean checkAuths) throws IOException; 119 120 /** 121 * Creates VisibilityExpEvaluator corresponding to given Authorizations. <br> 122 * Note: This will be concurrently called from multiple threads and implementation should take 123 * care of thread safety. 124 * @param authorizations 125 * Authorizations for the read request 126 * @return The VisibilityExpEvaluator corresponding to the given set of authorization labels. 127 */ 128 VisibilityExpEvaluator getVisibilityExpEvaluator(Authorizations authorizations) 129 throws IOException; 130 131 /** 132 * System checks for user auth during admin operations. (ie. Label add, set/clear auth). The 133 * operation is allowed only for users having system auth. Also during read, if the requesting 134 * user has system auth, he can view all the data irrespective of its labels. 135 * @param user 136 * User for whom system auth check to be done. 137 * @return true if the given user is having system/super auth 138 */ 139 boolean havingSystemAuth(User user) throws IOException; 140 141 /** 142 * System uses this for deciding whether a Cell can be deleted by matching visibility expression 143 * in Delete mutation and the cell in consideration. Also system passes the serialization format 144 * of visibility tags in Put and Delete.<br> 145 * Note: This will be concurrently called from multiple threads and implementation should take 146 * care of thread safety. 147 * @param putVisTags 148 * The visibility tags present in the Put mutation 149 * @param putVisTagFormat 150 * The serialization format for the Put visibility tags. A <code>null</code> value for 151 * this format means the tags are written with unsorted label ordinals 152 * @param deleteVisTags 153 * - The visibility tags in the delete mutation (the specified Cell Visibility) 154 * @param deleteVisTagFormat 155 * The serialization format for the Delete visibility tags. A <code>null</code> value for 156 * this format means the tags are written with unsorted label ordinals 157 * @return true if matching tags are found 158 * @see VisibilityConstants#SORTED_ORDINAL_SERIALIZATION_FORMAT 159 */ 160 boolean matchVisibility(List<Tag> putVisTags, Byte putVisTagFormat, List<Tag> deleteVisTags, 161 Byte deleteVisTagFormat) throws IOException; 162 163 /** 164 * Provides a way to modify the visibility tags of type {@link TagType} 165 * .VISIBILITY_TAG_TYPE, that are part of the cell created from the WALEdits 166 * that are prepared for replication while calling 167 * {@link org.apache.hadoop.hbase.replication.ReplicationEndpoint} 168 * .replicate(). 169 * {@link org.apache.hadoop.hbase.security.visibility.VisibilityReplicationEndpoint} 170 * calls this API to provide an opportunity to modify the visibility tags 171 * before replicating. 172 * 173 * @param visTags 174 * the visibility tags associated with the cell 175 * @param serializationFormat 176 * the serialization format associated with the tag 177 * @return the modified visibility expression in the form of byte[] 178 * @throws IOException 179 */ 180 byte[] encodeVisibilityForReplication(final List<Tag> visTags, 181 final Byte serializationFormat) throws IOException; 182 183 }