The Catholic Church does not teach that one only must be a “good” person to be saved. A man could never sin and attain to perfect natural goodness, and that would still not suffice for salvation (
“Except a man be born of water and of the Spirit, he cannot enter into the kingdom of God”, John 3:5). On the contrary, the Catholic Church teaches that one must be a member of the Catholic Church to be saved, since the Catholic Church is the only means of salvation.
“[The holy Roman church, founded on the words of our Lord and Saviour] firmly believes, professes and preaches that all those who are outside the catholic church,
not only pagans but also Jews or heretics and schismatics, cannot share in eternal life and will go into the everlasting fire which was prepared for the devil and his angels, unless they are joined to the catholic church before the end of their lives; that the unity of the ecclesiastical body is of such importance that only for those who abide in it do the church’s sacraments contribute to salvation and do fasts, almsgiving and other works of piety and practices of the Christian militia produce eternal rewards; and that nobody can be saved, no matter how much he has given away in alms and even if he has shed his blood in the name of Christ, unless he has persevered in the bosom and the unity of the catholic church.”
ewtn.com/library/COUNCILS/FLORENCE.HTM#5
This does not necessarily mean that God could not save someone outside the visible communion of the Church. The Catholic Encyclopedia article on the “Church” talks about this possibility.
"The doctrine is summed up in the phrase, Extra Ecclesiam nulla salus. This saying has been the occasion of so many objections that some consideration of its meaning seems desirable. It certainly does not mean that none can be saved except those who are in visible communion with the Church. The Catholic Church has ever taught that nothing else is needed to obtain justification than an act of perfect charity and of contrition. Whoever, under the impulse of actual grace, elicits these acts receives immediately the gift of sanctifying grace, and is numbered among the children of God. Should he die in these dispositions, he will assuredly attain heaven. It is true such acts could not possibly be elicited by one who was aware that God has commanded all to join the Church, and who nevertheless should willfully remain outside her fold. For love of God carries with it the practical desire to fulfill His commandments. But of those who die without visible communion with the Church, not all are guilty of willful disobedience to God’s commands. Many are kept from the Church by ignorance. Such may be the case of numbers among those who have been brought up in heresy. To others the external means of grace may be unattainable. Thus an excommunicated person may have no opportunity of seeking reconciliation at the last, and yet may repair his faults by inward acts of contrition and charity.
It should be observed that those who are thus saved are not entirely outside the pale of the Church. The will to fulfill all God’s commandments is, and must be, present in all of them. Such a wish implicitly includes the desire for incorporation with the visible Church: for this, though they know it not, has been commanded by God. They thus belong to the Church by desire (voto). Moreover, there is a true sense in which they may be said to be saved through the Church. In the order of Divine Providence, salvation is given to man in the Church: membership in the Church Triumphant is given through membership in the Church Militant. Sanctifying grace, the title to salvation, is peculiarly the grace of those who are united to Christ in the Church: it is the birthright of the children of God. The primary purpose of those actual graces which God bestows upon those outside the Church is to draw them within the fold. Thus, even in the case in which God saves men apart from the Church, He does so through the Church’s graces. They are joined to the Church in spiritual communion, though not in visible and external communion. In the expression of theologians, they belong to the soul of the Church, though not to its body. Yet the possibility of salvation apart from visible communion with the Church must not blind us to the loss suffered by those who are thus situated. They are cut off from the sacraments God has given as the support of the soul. In the ordinary channels of grace, which are ever open to the faithful Catholic, they cannot participate. Countless means of sanctification which the Church offers are denied to them. It is often urged that this is a stern and narrow doctrine. The reply to this objection is that the doctrine is stern, but only in the sense in which sternness is inseparable from love. It is the same sternness which we find in Christ’s words, when he said: “If you believe not that I am he, you shall die in your sin” (John 8:24). The Church is animated with the spirit of Christ; she is filled with the same love for souls, the same desire for their salvation. Since, then, she knows that the way of salvation is through union with her, that in her and in her alone are stored the benefits of the Passion, she must needs be uncompromising and even stern in the assertion of her claims. To fail here would be to fail in the duty entrusted to her by her Lord. Even where the message is unwelcome, she must deliver it."
newadvent.org/cathen/03744a.htm