hieunguyen30 commented on code in PR #518:
URL: https://github.com/apache/airavata-custos/pull/518#discussion_r4464543433


##########
connectors/LDAP/Provisioner/internal/operations/ensure_posix_account.go:
##########
@@ -0,0 +1,401 @@
+// 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 operations
+
+import (
+       "context"
+       "fmt"
+       "log/slog"
+       "regexp"
+       "strconv"
+
+       
"github.com/apache/airavata-custos/connectors/LDAP/Provisioner/internal/client"
+       "github.com/apache/airavata-custos/pkg/models"
+)
+
+// identitySourcePrefix is the user_identities.source prefix for
+// LDAP-assigned uidNumbers. The full source string is
+// identitySourcePrefix + ":" + CustosClusterID so a deployment
+// servicing multiple clusters caches each cluster's uidNumber
+// separately — the same Custos user can have different POSIX uids
+// on different clusters. Symmetric to the COmanage connector's
+// source="comanage" tag but scoped per cluster to prevent the
+// cross-cluster UID reuse that a flat source= would allow.
+const identitySourcePrefix = "ldap"
+
+// identitySource returns the fully-qualified user_identities.source
+// value for this connector instance's cluster.
+func (o *Orchestrator) identitySource() string {
+       if id := o.c.Config().CustosClusterID; id != "" {
+               return identitySourcePrefix + ":" + id
+       }
+       return identitySourcePrefix
+}
+
+// maxPosixUsernameLen is the traditional POSIX login-name cap. Matches
+// what the pkg/posix allocator already enforces on the AMIE side.
+const maxPosixUsernameLen = 32
+
+// validPosixUsername matches a lowercase POSIX-conformant login name.
+// Restricting to [a-z0-9_-] also happens to reject every RFC 4514 DN
+// metacharacter (comma, plus, quote, backslash, less/greater, semicolon,
+// equals, hash, space), so the RDN can be safely concatenated into
+// uid=<value>,<BaseDN> without DN escaping.
+var validPosixUsername = regexp.MustCompile(`^[a-z_][a-z0-9_-]*$`)
+
+// maxAllocRetries bounds how many times the orchestrator will re-allocate
+// after a uidNumber constraint violation from an out-of-band writer that
+// already holds our counter's next value. The persistent monotonic
+// counter serialises Custos-side races itself (InnoDB row lock on the
+// ldap_uid_sequence row), so retries are only reached against uids
+// claimed by processes outside this connector.
+const maxAllocRetries = 3
+
+// ensurePOSIXAccountImpl provisions a posixAccount entry (and, when
+// GroupBaseDN is configured, a matching posixGroup) for the given
+// ComputeClusterUser. Mirrors the COmanage connector's shape: resolve
+// the identity registry's assigned id, cache it in user_identities,
+// materialise the POSIX record, and add the primary group.
+//
+// Direct-LDAP path specifics:
+//   - The identity registry is a persistent monotonic counter
+//     (internal/store.UIDSequence, one row per cluster in
+//     ldap_uid_sequence). Never regresses on entry deletion, so a new
+//     user cannot inherit a deleted user's numeric uid.
+//   - gidnumber = uidnumber (one-group-per-user), same pattern the
+//     COmanage flow uses on the CoGroup identifier.
+//   - user_identities(source="ldap:<clusterID>", external_id=<uidNumber>)
+//     caches the assignment so re-provisioning the same user is O(1).
+//   - When GroupBaseDN is set, a posixGroup with cn=<LocalUsername>,
+//     gidNumber=<uidNumber> is created too; without GroupBaseDN the
+//     connector assumes auto-private-groups on the client side.

Review Comment:
   trimmed these, and I cleaned up the comments in the rest of the connector as 
well.
   



-- 
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