kumaab commented on code in PR #1096:
URL: https://github.com/apache/ranger/pull/1096#discussion_r3625789769


##########
common-utils/src/main/java/org/apache/ranger/plugin/util/SpiffeIdUtil.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Helper for validating a SPIFFE ID and extracting the service-account 
identity from it.
+ *
+ * <p>A SPIFFE ID is expected in the exact form {@code 
spiffe://<trust-domain>/ns/<namespace>/sa/<service-account>};
+ * for service-to-service authentication the receiving server trusts the 
workload
+ * identity carried in a header (e.g. {@code x-service-spiffe-id}) and uses
+ * the trailing service-account segment as the authenticated principal.
+ */
+public final class SpiffeIdUtil {
+    private static final String  HEADER_NAMES_SEP  = ",";
+
+    /**
+     * Matches {@code 
spiffe://<trust-domain>/ns/<namespace>/sa/<service-account>}.
+     *
+     * <p>The trust-domain is a DNS-style label set (lowercase alphanumerics, 
{@code -} and {@code .});
+     * the namespace and service-account are RFC-1123 labels (lowercase 
alphanumerics and {@code -},
+     * not starting or ending with {@code -}), matching Kubernetes naming. 
This deliberately excludes
+     * uppercase, whitespace and control characters so the extracted principal 
is well-formed.
+     * The service-account is exposed via the named group {@code sa}.
+     */
+    private static final Pattern SPIFFE_ID_PATTERN = Pattern.compile(

Review Comment:
   Good catch, thanks, I've fixed it now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to