Search in sources :

Example 6 with OpenShiftTarget

use of com.tremolosecurity.unison.openshiftv3.OpenShiftTarget in project OpenUnison by TremoloSecurity.

the class ListClusters method getSourceList.

@Override
public List<NVP> getSourceList(HttpFilterRequest request) throws Exception {
    List<TargetType> targets = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getTargets().getTarget();
    List<NVP> k8sTargets = new ArrayList<NVP>();
    for (TargetType tt : targets) {
        if (tt.getClassName().equalsIgnoreCase("com.tremolosecurity.unison.openshiftv3.OpenShiftTarget")) {
            OpenShiftTarget target = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(tt.getName()).getProvider();
            k8sTargets.add(new NVP(target.getLabel(), tt.getName()));
        }
    }
    return k8sTargets;
}
Also used : TargetType(com.tremolosecurity.config.xml.TargetType) ArrayList(java.util.ArrayList) NVP(com.tremolosecurity.util.NVP) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget)

Example 7 with OpenShiftTarget

use of com.tremolosecurity.unison.openshiftv3.OpenShiftTarget in project OpenUnison by TremoloSecurity.

the class K8sCrdInsert method search.

@Override
public void search(SearchInterceptorChain chain, DistinguishedName base, Int scope, Filter filter, ArrayList<Attribute> attributes, Bool typesOnly, Results results, LDAPSearchConstraints constraints) throws LDAPException {
    OpenShiftTarget k8s = null;
    try {
        k8s = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.k8sTarget).getProvider();
    } catch (ProvisioningException e1) {
        logger.error("Could not retrieve kubernetes target", e1);
        throw new LDAPException("Could not connect to kubernetes", LDAPException.OPERATIONS_ERROR, LDAPException.resultCodeToString(LDAPException.OPERATIONS_ERROR));
    }
    // base search
    if (scope.getValue() == 0) {
        // dir root
        if (base.getDN().equals(this.baseDN)) {
            ArrayList<Entry> ret = new ArrayList<Entry>();
            ret.add(new Entry(EntryUtil.createBaseEntry(this.baseDN)));
            chain.addResult(results, new IteratorEntrySet(ret.iterator()), base, scope, filter, attributes, typesOnly, constraints);
            return;
        } else {
            String name = ((RDN) base.getDN().getRDNs().get(0)).getValue();
            loadUserFromK8sCrd(chain, base, scope, filter, attributes, typesOnly, results, constraints, k8s, name, base.getDN().toString(), true);
            return;
        }
    } else if (scope.getValue() == 1) {
        if (base.getDN().equals(this.baseDN)) {
            String name = userFromFilter(filter.getRoot());
            loadUserFromK8sCrd(chain, base, scope, filter, attributes, typesOnly, results, constraints, k8s, name, new StringBuilder().append("uid=").append(name).append(",").append(base.getDN().toString()).toString(), false);
            return;
        }
    } else {
        // only subtree left
        if (logger.isDebugEnabled()) {
            logger.debug("orirignal filter : '" + filter.getRoot().toString() + "'");
        }
        String name = userFromFilter(filter.getRoot());
        loadUserFromK8sCrd(chain, base, scope, filter, attributes, typesOnly, results, constraints, k8s, name, new StringBuilder().append("uid=").append(name).append(",").append(this.baseDN.toString()).toString(), false);
        return;
    }
}
Also used : IteratorEntrySet(net.sourceforge.myvd.util.IteratorEntrySet) Entry(net.sourceforge.myvd.types.Entry) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ArrayList(java.util.ArrayList) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget) RDN(com.novell.ldap.util.RDN)

Example 8 with OpenShiftTarget

use of com.tremolosecurity.unison.openshiftv3.OpenShiftTarget in project OpenUnison by TremoloSecurity.

the class K8sSessionStore method deleteAllSessions.

@Override
public void deleteAllSessions(String sessionId) throws Exception {
    String sessionIdName = new StringBuilder().append("x").append(sessionId).append("x").toString();
    OpenShiftTarget k8s = null;
    try {
        k8s = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.k8sTarget).getProvider();
    } catch (ProvisioningException e1) {
        logger.error("Could not retrieve kubernetes target", e1);
        throw new ProvisioningException("Could not connect to kubernetes", e1);
    }
    String url = new StringBuilder().append("/apis/openunison.tremolo.io/v1/namespaces/").append(this.nameSpace).append("/oidc-sessions/").append(sessionIdName).toString();
    try {
        HttpCon con = k8s.createClient();
        try {
            String jsonResp = k8s.callWS(k8s.getAuthToken(), con, url);
            JSONObject root = (JSONObject) new JSONParser().parse(jsonResp);
            if (root.containsKey("kind") && root.get("kind").equals("Status") && ((Long) root.get("code")) == 404) {
                logger.warn(new StringBuilder().append("Session ID ").append(sessionId).append(" does not exist"));
                return;
            }
            JSONObject metadata = (JSONObject) root.get("metadata");
            JSONObject labels = (JSONObject) metadata.get("labels");
            String dnHash = (String) labels.get("tremolo.io/user-dn");
            url = new StringBuilder().append("/apis/openunison.tremolo.io/v1/namespaces/").append(this.nameSpace).append("/oidc-sessions?labelSelector=tremolo.io%2Fuser-dn%3D").append(dnHash).toString();
            jsonResp = k8s.callWSDelete(k8s.getAuthToken(), con, url);
            if (logger.isDebugEnabled()) {
                logger.debug("json response from deleting object : " + jsonResp);
            }
        } finally {
            con.getHttp().close();
            con.getBcm().close();
        }
    } catch (Exception e) {
        logger.error("Could not search k8s", e);
        throw new Exception("Error searching kubernetes", e);
    }
}
Also used : HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JSONObject(org.json.simple.JSONObject) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget) JSONParser(org.json.simple.parser.JSONParser) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Example 9 with OpenShiftTarget

use of com.tremolosecurity.unison.openshiftv3.OpenShiftTarget in project OpenUnison by TremoloSecurity.

the class K8sSessionStore method deleteSession.

@Override
public void deleteSession(String sessionId) throws Exception {
    String sessionIdName = new StringBuilder().append("x").append(sessionId).append("x").toString();
    OpenShiftTarget k8s = null;
    try {
        k8s = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.k8sTarget).getProvider();
    } catch (ProvisioningException e1) {
        logger.error("Could not retrieve kubernetes target", e1);
        throw new ProvisioningException("Could not connect to kubernetes", e1);
    }
    String url = new StringBuilder().append("/apis/openunison.tremolo.io/v1/namespaces/").append(this.nameSpace).append("/oidc-sessions/").append(sessionIdName).toString();
    try {
        HttpCon con = k8s.createClient();
        try {
            String jsonResp = k8s.callWSDelete(k8s.getAuthToken(), con, url);
            if (logger.isDebugEnabled()) {
                logger.debug("json response from deleting object : " + jsonResp);
            }
        } finally {
            con.getHttp().close();
            con.getBcm().close();
        }
    } catch (Exception e) {
        logger.error("Could not search k8s", e);
        throw new Exception("Error searching kubernetes", e);
    }
}
Also used : HttpCon(com.tremolosecurity.provisioning.util.HttpCon) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Example 10 with OpenShiftTarget

use of com.tremolosecurity.unison.openshiftv3.OpenShiftTarget in project OpenUnison by TremoloSecurity.

the class K8sSessionStore method resetSession.

@Override
public void resetSession(OidcSessionState session) throws Exception {
    String sessionIdName = new StringBuilder().append("x").append(session.getSessionID()).append("x").toString();
    OpenShiftTarget k8s = null;
    try {
        k8s = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.k8sTarget).getProvider();
    } catch (ProvisioningException e1) {
        logger.error("Could not retrieve kubernetes target", e1);
        throw new ProvisioningException("Could not connect to kubernetes", e1);
    }
    String url = new StringBuilder().append("/apis/openunison.tremolo.io/v1/namespaces/").append(this.nameSpace).append("/oidc-sessions/").append(sessionIdName).toString();
    try {
        HttpCon con = k8s.createClient();
        try {
            String jsonResp = k8s.callWS(k8s.getAuthToken(), con, url);
            if (logger.isDebugEnabled()) {
                logger.debug("json response from deleting object : " + jsonResp);
            }
            Map ret = gson.fromJson(jsonResp, Map.class);
            Map obj = new HashMap();
            Map spec = (Map) ret.get("spec");
            obj.put("spec", spec);
            if (spec == null) {
                return;
            }
            spec.put("encrypted_id_token", session.getEncryptedIdToken());
            spec.put("encrypted_access_token", session.getEncryptedAccessToken());
            spec.put("refresh_token", session.getRefreshToken());
            spec.put("expires", ISODateTimeFormat.dateTime().print(session.getExpires()));
            jsonResp = k8s.callWSPatchJson(k8s.getAuthToken(), con, url, gson.toJson(obj));
            if (logger.isDebugEnabled()) {
                logger.debug("json response from patch : '" + jsonResp + "'");
            }
        } finally {
            con.getHttp().close();
            con.getBcm().close();
        }
    } catch (Exception e) {
        logger.error("Could not search k8s", e);
        throw new Exception("Error searching kubernetes", e);
    }
}
Also used : HttpCon(com.tremolosecurity.provisioning.util.HttpCon) HashMap(java.util.HashMap) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget) HashMap(java.util.HashMap) Map(java.util.Map) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Aggregations

OpenShiftTarget (com.tremolosecurity.unison.openshiftv3.OpenShiftTarget)36 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)30 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)27 JSONObject (org.json.simple.JSONObject)18 ArrayList (java.util.ArrayList)13 JSONParser (org.json.simple.parser.JSONParser)13 HashMap (java.util.HashMap)12 IOException (java.io.IOException)11 Workflow (com.tremolosecurity.provisioning.core.Workflow)9 LDAPException (com.novell.ldap.LDAPException)7 List (java.util.List)7 Map (java.util.Map)7 Attribute (com.tremolosecurity.saml.Attribute)6 GitFile (com.tremolosecurity.provisioning.tasks.dataobj.GitFile)5 JSONArray (org.json.simple.JSONArray)4 ParseException (org.json.simple.parser.ParseException)4 Gson (com.google.gson.Gson)3 LDAPEntry (com.novell.ldap.LDAPEntry)3 K8sUser (com.tremolosecurity.myvd.dataObj.K8sUser)3 User (com.tremolosecurity.provisioning.core.User)3