|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.hadoop.ozone.debug.kerberos; |
| 19 | + |
| 20 | +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED_DEFAULT; |
| 21 | +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_AUTHORIZATION_ENABLED; |
| 22 | +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SECURITY_ENABLED_KEY; |
| 23 | + |
| 24 | +import org.apache.hadoop.fs.CommonConfigurationKeysPublic; |
| 25 | +import org.apache.hadoop.hdds.HddsConfigKeys; |
| 26 | +import org.apache.hadoop.hdds.conf.OzoneConfiguration; |
| 27 | +import org.apache.hadoop.ozone.OzoneConfigKeys; |
| 28 | +import org.apache.hadoop.ozone.om.OMConfigKeys; |
| 29 | + |
| 30 | +/** |
| 31 | + * Validates Ozone and Hadoop RPC authorization configuration. |
| 32 | + * Checks whether Hadoop authorization and Ozone ACL settings are enabled |
| 33 | + * and properly configured. |
| 34 | + * Missing or disabled authorization is reported as a warning. |
| 35 | + */ |
| 36 | +public class AuthorizationProbe extends ConfigProbe { |
| 37 | + |
| 38 | + @Override |
| 39 | + public String name() { |
| 40 | + return "Authorization Configuration"; |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public ProbeResult test(OzoneConfiguration conf) { |
| 45 | + |
| 46 | + // Print relevant configs |
| 47 | + print(conf, OZONE_SECURITY_ENABLED_KEY); |
| 48 | + print(conf, OZONE_AUTHORIZATION_ENABLED); |
| 49 | + print(conf, OzoneConfigKeys.OZONE_ACL_ENABLED); |
| 50 | + print(conf, OzoneConfigKeys.OZONE_ACL_AUTHORIZER_CLASS); |
| 51 | + |
| 52 | + print(conf, CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION); |
| 53 | + print(conf, OMConfigKeys.OZONE_OM_SECURITY_CLIENT_PROTOCOL_ACL); |
| 54 | + |
| 55 | + print(conf, HddsConfigKeys.HDDS_SECURITY_CLIENT_DATANODE_CONTAINER_PROTOCOL_ACL); |
| 56 | + print(conf, HddsConfigKeys.HDDS_SECURITY_CLIENT_SCM_CONTAINER_PROTOCOL_ACL); |
| 57 | + print(conf, HddsConfigKeys.HDDS_SECURITY_CLIENT_SCM_BLOCK_PROTOCOL_ACL); |
| 58 | + print(conf, HddsConfigKeys.HDDS_SECURITY_CLIENT_SCM_CERTIFICATE_PROTOCOL_ACL); |
| 59 | + |
| 60 | + ProbeResult result = ProbeResult.PASS; |
| 61 | + |
| 62 | + // Validate Ozone security if enabled |
| 63 | + boolean ozoneSecurityEnabled = conf.getBoolean(OZONE_SECURITY_ENABLED_KEY, |
| 64 | + OzoneConfigKeys.OZONE_SECURITY_ENABLED_DEFAULT); |
| 65 | + |
| 66 | + // If security disabled, no need to check further. |
| 67 | + if (!ozoneSecurityEnabled) { |
| 68 | + warn("Ozone security is disabled (" |
| 69 | + + OZONE_SECURITY_ENABLED_KEY + "=" + ozoneSecurityEnabled + ". " |
| 70 | + + "Authorization checks are not enforced in non-secure mode."); |
| 71 | + return ProbeResult.WARN; // not a failure |
| 72 | + } |
| 73 | + |
| 74 | + // Validate Ozone authorization(master switch) |
| 75 | + boolean ozoneAuthEnabled = conf.getBoolean(OZONE_AUTHORIZATION_ENABLED, |
| 76 | + OzoneConfigKeys.OZONE_AUTHORIZATION_ENABLED_DEFAULT); |
| 77 | + |
| 78 | + if (!ozoneAuthEnabled) { |
| 79 | + warn("Ozone authorization is disabled (" |
| 80 | + + OZONE_AUTHORIZATION_ENABLED + "=" + ozoneAuthEnabled + ". " |
| 81 | + + "No admin or ACL checks will be enforced."); |
| 82 | + result = ProbeResult.WARN; |
| 83 | + } |
| 84 | + |
| 85 | + // Validate Hadoop authorization |
| 86 | + boolean hadoopAuthEnabled = conf.getBoolean( |
| 87 | + CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false); |
| 88 | + |
| 89 | + if (!hadoopAuthEnabled) { |
| 90 | + warn("Hadoop authorization is disabled"); |
| 91 | + result = ProbeResult.WARN; |
| 92 | + } |
| 93 | + |
| 94 | + // Validate Ozone ACLs enforcement |
| 95 | + boolean ozoneAclEnabled = conf.getBoolean( |
| 96 | + OzoneConfigKeys.OZONE_ACL_ENABLED, OZONE_ACL_ENABLED_DEFAULT); |
| 97 | + |
| 98 | + if (!ozoneAclEnabled) { |
| 99 | + warn("Ozone ACLs are disabled while authorization is enabled. " |
| 100 | + + "Only admin privilege checks will be enforced."); |
| 101 | + result = ProbeResult.WARN; |
| 102 | + } |
| 103 | + |
| 104 | + return result; |
| 105 | + } |
| 106 | +} |
0 commit comments